我正在寻找一个简单的UI来显示我一直在研究的项目的结果。简单的显示(我希望在其上构建)是一个启动画面,通向画廊,您可以从中浏览许多.png文件(图形)。
我希望把它放在我的第二个屏幕上(目前它由两个按钮组成。)我不是要找任何人的完整解决方案,但是一些指导将不胜感激。我们的想法是第二个屏幕链接到包含图像的目录,然后可以循环显示。
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
# Create both screens. Please note the root.manager.current: this is how
# you can control the ScreenManager from kv. Each screen has by default a
# property manager that gives you the instance of the ScreenManager used.
Builder.load_string("""
<MenuScreen>:
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'collage.png'
BoxLayout:
padding: [100, 100, 100, 100]
Button:
text: 'Go to Gallery'
on_press: root.manager.current = 'settings'
size_hint: 0.1, 0.25
pos_hint: {'center_x':.5, 'center_y':.2}
<GalleryScreen>:
BoxLayout:
Button:
text: 'My settings button'
Button:
text: 'Back to menu'
on_press: root.manager.current = 'menu'
""")
# Declare both screens
class MenuScreen(Screen):
pass
class GalleryScreen(Screen):
pass
# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(GalleryScreen(name='settings'))
class TestApp(App):
def build(self):
return sm
if __name__ == '__main__':
TestApp().run()
新的kivy,并且在时间限制下,这可能解释了广泛的问题,任何帮助都会受到赞赏。