#仅供参考
#绑定界面
cdtimer = CountDown(root)
#设置倒计时长
cdtimer.start_timer(120)
class CountDown(object):
def __init__(self, master=None):
self.root = master
self.total_sec = 99999
self.root.resizable(width=False, height=False)
self.updatetime()
def updatetime(self):
self.labelA = Label(self.root, text='')
self.labelA.place(x=0, y=0)#设置位置,现在表示在root窗口x=0,y=0位置
self.labelA.pack()
def updateA(self):
self.labelA.place(x=0, y=0)#设置位置
self.total_sec -= 1
time_str = ""
if self.total_sec > 0:
time_str = '倒计时:' + str(self.total_sec)
self.root.after(1000, self.updateA)
else:
pygame.mixer.Sound.play(finishSound)
messagebox.showinfo(title='提示',message='时间到,游戏结束')
self.labelA.configure(text=time_str)
def start_timer(self,total_sec):
self.total_sec = total_sec
self.updateA()
python:游戏倒计时器
于 2022-04-06 22:05:41 首次发布