我是 python 新手,我正在尝试在单击按钮时制作倒数计时器。但我希望这个倒计时计时器开始倒计时并将当前倒计时值放在文本区域中。我还需要应用程序的其余部分在此倒计时运行时不休眠。到目前为止,它将在控制台中输出倒计时,但会冻结应用程序的其余部分。有人可以指出我正确的方向吗?
from Tkinter import *
import time
import threading
import thread
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.getvalue = Button(frame, text="Get the Text Area", command=self.thevalue)
self.getvalue.pack(side=LEFT)
self.text_area = Entry()
self.text_area.pack(side=RIGHT)
def thevalue(self):
print "In the value"
try:
t = threading.Thread(target=self.print_time("I am in print_time"))
t.daemon = True
t.start()
except:
print "Error: unable to start thread"
def print_time(self,bleh):
print bleh
print "The text area value is %s" % self.text_area.get()
boom=5
while boom >0:
time.sleep(1)
self.text_area.delete(0, END)
self.text_area.insert(0, boom)
print(boom)
boom -=1
root = Tk()
app = App(root)
root.mainloop()