【发布时间】:2016-02-20 20:16:14
【问题描述】:
您好,我不知道下一步该做什么。 我希望警报标签在 Tkinter 小部件打开后更新时间。 任何想法都值得赞赏。我在网上查看了线程,但他们似乎以完全不同的方式来做这件事,我相信我有一种简单的方法可以让这个时钟正常工作。
from Tkinter import *
import time
#Window
alarm_window = Tk()
#Title
alarm_window.title('Alarm')
def off_press():
alarm_window.destroy()
#Alarm Class
class Clock(object):
def __init__ (self, time, sleep):
self.time = time
self.sleep = sleep
print "The time and date is %s" % (self.time) #temporary to see if it's working
#Alarm
alarm_label = Label(alarm_window, text = self.time)
alarm_label.grid (row = 0, column = 1)
def refresh_time():
for each in range(2): #only temporary until I find a way to make the label update
alarm = Clock(time.ctime(), time.sleep(1))
#Off Button
off = Button(alarm_window, text = "Off", command = off_press)
off.grid (row = 1, column = 2)
#Snooze
snooze = Button(alarm_window, text = "Snooze")
snooze.grid (row= 1, column = 0)
#Run Program
refresh_time()
alarm_window.mainloop()
【问题讨论】:
标签: python tkinter label clock