python 控件显示时间_设置tkinter标签以显示倒计时时间
我正在嘗試做一個pomodoro計時器,它將顯示不同的倒計時點擊三個按鈕選項之一。在
這里的問題是,每次我在之前單擊一個按鈕之后單擊一個按鈕,標簽都會為顯示哪個計時器而煩惱。它試圖同時顯示兩個定時器倒計時。在
當我點擊另一個按鈕時,我需要標簽停止顯示第一個按鈕的定時器倒計時。我的代碼是:from tkinter import *
class Application(Frame):
def __init__(self,master):
super(Application,self).__init__(master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.labelvariable = StringVar()
self.labelvariable.set("25:00")
self.thelabel = Label(self,textvariable = self.labelvariable,font=('Helvetica',50))
self.thelabel.pack(side=TOP)
self.firstButton = Button(self,text="pomodoro",command=self.pomodoro)
self.firstButton.pack(side=LEFT)
self.secondButton = Button(self,text="short break",command=self.shortBreak)
self.secondButton.pack(side=LEFT)
self.thirdButton = Button(self,text="long break",command=self.longBreak)
self.thirdButton.pack(side=LEFT)
def pomodoro(self):
countdown(1500)
def shortBreak(self):
countdown(300)
def longBreak(self):
countdown(600)
def countdown(timeInSeconds):
mins,secs = divmod(timeInSeconds,60)
timeformat = "{0:02d}:{1:02d}".format(mins,secs)
app.labelvariable.set(timeformat)
root.after(1000,countdown,timeInSeconds-1)
if __name__ == '__main__':
root = Tk()
root.title("Timer")
app = Application(root)
root.mainloop()
總結
以上是生活随笔為你收集整理的python 控件显示时间_设置tkinter标签以显示倒计时时间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python construct 字符串
- 下一篇: wp转shp_【收藏】空间数据格式转换方