私は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()