【发布时间】:2018-08-12 14:16:29
【问题描述】:
在 Kivy for Python 中,我想知道如何安排屏幕在指定秒数后自动转换到新屏幕。我使用 Kivy Clock 工具安排了一个事件,但是当我运行应用程序时它对我的代码没有响应。这是我的 main.py 代码:
class Opening_Screen():
def __init__(self, **kwargs):
super(Opening_Screen, self).__init__(**kwargs)
Clock.schedule_once(self.change_screen, 5)
def change_screen(self, *kwargs):
root.current = 'Options_Screen'
class Patient_Care(App):
pass
if __name__ == '__main__':
Patient_Care().run()
这是我对应的.kv文件代码:
#:import C kivy.utils.get_color_from_hex
#:import RiseInTransition kivy.uix.screenmanager.RiseInTransition
ScreenManager:
transition: RiseInTransition()
Screen:
name: 'Opening_Screen'
Label:
text:'Welcome'
font_size: 40
color: 0, 0, 1, 1
pos:(self.x / 2, 250)
Button:
size_hint: (1, None)
height: 90
font_size: 30
background_normal: 'button_normal.png'
background_down: 'button_down.png'
border: (2, 2, 2, 2)
text: 'Continue'
on_press: root.current = 'Options_Screen'
Screen:
name: 'Options_Screen'
GridLayout:
padding: 15
rows: 5
spacing: 10
Button:
text:'Option 1'
Button:
text:'Option 2'
Button:
text: 'Option 3'
Button:
text: 'Option 4'
Button:
text: 'Option 5'
在我的 .kv 文件中,我有另一个名为“Options_Screen”的屏幕。我想在 5 秒后从“Opening_Screen”切换到选项屏幕。当我为 Opening_Screen 创建一个按钮并将其设计为切换到 Options_Screen (on_press: root.current = 'Options_Screen') 时,转换工作。但是,我的目标是使用 Clock.schedule_once 函数在不按下按钮的情况下自动切换来动态切换。
【问题讨论】:
-
显示你的 .kv!!!!
-
Opening_Screen 继承了什么类?
-
你的 .kv 名称是什么?
-
我的 .kv 名称是 patient_care.kv