目的是在我的主屏幕上有一个按钮,按下时会打开一个延迟屏幕。然后需要 5 秒的时间延迟,然后屏幕将返回主屏幕。
我的问题是与按钮按下相关的任何时间延迟,阻止延迟屏幕打开
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.uix.floatlayout import FloatLayout
import time
Builder.load_string("""
<MainScreen>:
name: "main"
FloatLayout:
canvas:
Rectangle:
pos: self.pos
size: self.size
Button:
background_color: 1, .8, .3, 1
text:'Home'
size_hint: .8,.2
pos_hint: {'center_x':.5,'y':.1}
on_press:root.manager.current = "delay"
<TimeDelay>:
name: "delay"
FloatLayout:
Button:
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "delay"
pos_hint: {'center_x':0.5,'top':0.5}
on_press:root.manager.current = "main"
""")
class MainScreen(Screen):
pass
class TimeDelay(Screen):
time.sleep(5)
sm.switch_to('main')
sm = ScreenManager()
sm.add_widget(MainScreen(name='main'))
sm.add_widget(TimeDelay(name='delay'))
class timedelayapp(App):
def build(self):
return sm
if __name__ == "__main__":
timedelayapp().run()