在這個腳本中,標簽文本在2秒后才會改變。我需要time.sleep(2),因為我正在使用python-vlc,我想在播放音頻之前改變標簽文本。
import tkinter
import time
class MyGUI。
def __init__(self):
self.root = tkinter.Tk()
self.testLabel = tkinter.Label(self.root, text = 'I am suhail')
self.changetextBtn = tkinter.Button(self.root,text="change txt" , command=self.chngbtn)
self.testLabel.pack()
self.changetextBtn.pack()
self.n_clicks =0
tkinter.mainloop()
def chngbtn(self)。
self.testLabel["text"] = f'changed text: {self.n_clicks} times'
self.n_clicks =1
time.sleep(2)
myGUI = MyGUI()
看到我正在嘗試的代碼。
uj5u.com熱心網友回復:
你可以使用self.root.update()或者self.root.update_idletasks()來重繪 它,在改變標簽后立即進行。
def chngbtn(self)。
self.testLabel["text"] = f'changed text: {self.n_clicks} times'
self.root.update() # or self.root.update_idletasks()
self.n_clicks =1
time.sleep(2)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330594.html
標籤:
上一篇:tkinter標簽的框架內的框架
