【发布时间】:2016-05-10 22:59:41
【问题描述】:
背景:我一直在学习 Python - 并通过它 - Kivy,通过制作一个应用程序。我一直在使用 .kv 文件和 Builder.load_string 方法来创建我的图形,但我决定尝试仅使用 python,并将我的所有布局都移到 python 中。
问题:当我开始使用屏幕时,我无法将正确的代码绑定到按钮以进行屏幕转换。当我写这行时,'self.manager.etc...' 自动完成向我显示要使用的有效属性列表。
所以在“自我”之后。它表明我可以使用“经理”,在“经理”之后。它不认为屏幕的管理器具有“当前”或“过渡”属性。我一定搞砸了如何将屏幕连接到经理,但我无法理解如何。
class HomePage(Screen):
def __init__(self, **kwargs):
super(HomePage, self).__init__(**kwargs)
layout = FloatLayout()
notification = Label(text='upcoming: ....', font_size='16sp', size_hint=(0,0), pos_hint={'center_x':.5, 'top':0.9})
layout.add_widget(notification)
button_row=BoxLayout(size_hint_y=.1, spacing=20)
profile_button=Label(text='Profile')
button_row.add_widget(profile_button)
layout.add_widget(button_row)
self.add_widget(layout)
def transit():
self.manager.current = profile_button # <- this should work, right?
profile_button.bind(on_press=transit)
class ScreenApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(HomePage(name='home'))
return sm
if __name__ == "__main__":
ScreenApp().run()
【问题讨论】:
标签: android python screen kivy