本文整理汇总了Python中tkinter.Button.update方法的典型用法代码示例。如果您正苦于以下问题:Python Button.update方法的具体用法?Python Button.update怎么用?Python Button.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Button
的用法示例。
在下文中一共展示了Button.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Pomodoro
# 需要导入模块: from tkinter import Button [as 别名]
# 或者: from tkinter.Button import update [as 别名]
class Pomodoro(Frame):
def __init__(self, parent, abspath):
super().__init__(parent)
self.root = parent
self.abspath = abspath
self.work_count = 0
# Tk variables
self.tagVar = StringVar()
self.tagVar.set("")
self.actionVar = StringVar()
self.actionVar.set(WORK)
self.displayVar = StringVar()
self.displayVar.set("00:00")
self.initUI()
def initUI(self):
# toplevel
self.root.title("PomodoroPy")
self.root.resizable(0, 0)
# main frame
self.pack()
self.timeLabel = Label(self, textvariable=self.displayVar)
self.timeLabel["background"] = YELLOW
self.timeLabel["padx"] = "10px"
self.timeLabel["font"] = "helvetica 48 bold"
self.timeLabel["fg"] = "gray"
self.timeLabel.pack(expand=True, fill=tk.X)
self.actionButton = Button(self)
self.actionButton["text"] = WORK
self.actionButton["font"] = "helvetica 16"
self.actionButton["command"] = lambda: self.action(
self.actionButton.cget("text"))
self.actionButton.pack(expand=True, fill=tk.X)
def action(self, action):
if action == WORK:
self.work_count += 1
self.timeLabel["fg"] = BLUE
self.actionButton["text"] = PAUSE
self.clock(T_WORK)
self.actionButton["text"] = BREAK
elif action == PAUSE:
self.timeLabel["fg"] = RED
self.actionButton["text"] = CONTINUE
elif action == CONTINUE:
self.timeLabel["fg"] = BLUE
self.actionButton["text"] = PAUSE
elif action == BREAK:
self.actionButton["state"] = "disable"
if self.work_count < 4:
self.timeLabel["fg"] = GREEN
self.clock(T_BREAK)
elif self.work_count >= 4:
self.timeLabel["fg"] = ORANGE
self.clock(T_LONG)
self.work_count = 0
self.actionButton["state"] = "normal"
self.actionButton["text"] = WORK
def clock(self, minutes):
finish = time() + minutes * 60
while(time() < finish):
self.actionButton.update()
if self.actionButton.cget("text") != CONTINUE:
seconds = finish - time()
remaining = gmtime(seconds)
self.displayVar.set(strftime("%M:%S", remaining))
self.update_idletasks()
sleep(1)
else:
finish = time() + seconds
self.playSound()
def playSound(self):
mixer.init()
soundPath = path.join(self.abspath, "sounds/alert2.mp3")
mixer.music.load(soundPath)
mixer.music.play()