日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 控件显示时间_设置tkinter标签以显示倒计时时间

發(fā)布時(shí)間:2025/4/5 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 控件显示时间_设置tkinter标签以显示倒计时时间 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我正在嘗試做一個(gè)pomodoro計(jì)時(shí)器,它將顯示不同的倒計(jì)時(shí)點(diǎn)擊三個(gè)按鈕選項(xiàng)之一。在

這里的問題是,每次我在之前單擊一個(gè)按鈕之后單擊一個(gè)按鈕,標(biāo)簽都會(huì)為顯示哪個(gè)計(jì)時(shí)器而煩惱。它試圖同時(shí)顯示兩個(gè)定時(shí)器倒計(jì)時(shí)。在

當(dāng)我點(diǎn)擊另一個(gè)按鈕時(shí),我需要標(biāo)簽停止顯示第一個(gè)按鈕的定時(shí)器倒計(jì)時(shí)。我的代碼是: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()

總結(jié)

以上是生活随笔為你收集整理的python 控件显示时间_设置tkinter标签以显示倒计时时间的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。