我尝试从Thread更新标签的文本,但是没有成功。下面是代码的一个示例
def search_callback():
class Holder(object):
done = False
holder = Holder()
t = threading.Thread(target=animate, args=(holder,))
t.start()
#long process here
holder.done = True # inform thread long process is finished
def animate(holder):
for c in itertools.cycle(['|', '/', '-', '\\']):
if holder.done:
break
print('\rRecherche ' + c) # This work!
label_wait.configure(text='\rRecherche ' + c) # this doesn't work nothing appear in my label
time.sleep(0.5)
label_wait.configure(text='\rTerminé! ')
print('\rTerminé! ')
但是我不明白为什么label_wait.configure
不工作,print
也工作得很好。
我试过在我的线程中使用after
方法,但它没有改变。
1条答案
按热度按时间nhaq1z211#
线程,但它不工作
不用担心
Thread
False
更改为holder.done = False
label_wait.configure(text='\rTerminé! ')
和print()
'
片段:
截图: