Tkinter는 단일 스레드 루프에서 UI를 업데이트하므로 대기 기간 동안 컨트롤을 Tkinter로 넘겨야합니다.
구성 호출간에 잠시 기다리면 UI가 중단됩니다.
언급 한대로 after
은 원하는 방법입니다. 다음과 같이 시도해보세요.
try:
import Tkinter as tkinter # Python 2
except ImportError:
import tkinter # Python 3
import itertools
class MyApplication(object):
def __init__(self):
# Create and pack widgets
self.root = tkinter.Tk()
self.label = tkinter.Label(self.root)
self.button = tkinter.Button(self.root)
self.label.pack(expand=True)
self.button.pack()
self.label['text'] = 'Initial'
self.button['text'] = 'Update Label'
self.button['command'] = self.wait_update_label
# Configure label values
self.label_values = itertools.cycle(['Hello', 'World'])
def launch(self):
self.root.mainloop()
def wait_update_label(self):
def update_label():
value = next(self.label_values)
self.label['text'] = value
update_period_in_ms = 1500
self.root.after(update_period_in_ms, update_label)
self.label['text'] = 'Waiting...'
if __name__ == '__main__':
app = MyApplication()
app.launch()