[英]how to make a countdown label that start after i press button kivy
My ideas is to make a countdown label that start after i press button Scenario: 1.press button 2.wait one second 3.label change to 1 4.wait one second 5.label change to 2 6.wait one second 7.label更改为 3
我一直在尝试
千伏:
<PlayScreen>:
name: 'play'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: 'shuiitplaymenubg.jpg'
MDIconButton:
pos_hint: {'center_x':0.275,'center_y':0.16}
on_press: root.countdown()
icon: "startlogo.png"
user_font_size: 62
MDIconButton:
pos_hint: {'center_x':0.275,'center_y':0.06}
on_press: root.manager.current = 'menu'
user_font_size: 62
icon: "backlogo.png"
Label:
id: countdown_label
text: -
pos_hint: {'center_x':0.82,'center_y':0.585}
派:
class PlayScreen(Screen):
def countdown(self):
def countdownone(self):
self.ids.countdown_label.text = "3"
def countdowntwo(self):
self.ids.countdown_label.text = "2"
def countdownthree(self):
self.ids.countdown_label.text = "1"
Clock.schedule_once(countdownone(), 1)
Clock.schedule_once(countdowntwo(), 2)
Clock.schedule_once(countdownthree(), 3)
结果:给出错误
您的代码有几个问题:
Clock.schedule
方法调用的方法必须接受dt
参数(或使用*args
)。Clock.schedule
中引用的方法必须是对方法的引用。 使用countdownone()
不是对该方法的引用,它实际上执行该方法并尝试安排返回值(即None
)。self
参数。 外部方法中的self
在内部方法中可用。 因此,使用上述内容的PlayScreen
class 的修改版本:
class PlayScreen(Screen):
def countdown(self):
def countdownone(dt):
self.ids.countdown_label.text = "3"
def countdowntwo(dt):
self.ids.countdown_label.text = "2"
def countdownthree(dt):
self.ids.countdown_label.text = "1"
Clock.schedule_once(countdownone, 1)
Clock.schedule_once(countdowntwo, 2)
Clock.schedule_once(countdownthree, 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.