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 change to 3
What Ive been try
kv:
<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}
Py:
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)
Result: Giving error
Several problems with your code:
Clock.schedule
methods must accept a dt
argument (or use *args
).Clock.schedule
must be references to a method. Using countdownone()
is not a reference to that method, it actually executes that method and tries to schedule the return value (which is None
).self
argument in a nested function. The self
from the outer method is available in the inner method. So a modified version of your PlayScreen
class using the above:
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.