Kivy:图像滚动 [英] Kivy: Image scrolling
本文介绍了Kivy:图像滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的代码:
from kivy.app import App
from kivy.uix.image import Image
class TutorialApp(App):
def build(self):
l=Image(source='kivy.jpg', keep_ratio=True)
return l
if __name__ == "__main__":
TutorialApp().run()
我得到以下结果:
我希望图像的宽度等于屏幕的宽度(而不会失去宽高比).我还需要垂直滚动(以查看完整图像).
I want to image width equal to the width of the screen (without losing the aspect ratio). I also need vertical scrolling (to view full image).
结果应该是这样的:
该怎么做?
P.S.对不起,我的英语不好
P.S. Sorry for my bad English
推荐答案
To make an image or anything scrollable, use ScrollView:
from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
class TutorialApp(App):
def build(self):
sv = ScrollView(size=Window.size)
l = Image(
source='kivy.jpg',
size_hint=(None, None),
keep_ratio=True,
size=Window.size
)
sv.add_widget(l)
return sv
if __name__ == "__main__":
TutorialApp().run()
将size_hint
设置为(无,无"),然后定义固定的size
,即使将来更改,也可以保留原始窗口大小.
Setting size_hint
to (None, None) and then defining fixed size
allows to keep the original window size, even if it is changes in future.
这篇关于Kivy:图像滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文