简体   繁体   English

Tkinter标签未更新

[英]Tkinter Label doesn't update

Can anyone shed some light on why this wouldn't update label3 ? 任何人都可以阐明为什么这不会更新label3吗?

self.label3Text = StringVar()
self.label3Text.set("0/0")
self.label3 = Label(textvariable=self.label3Text)
self.label3.pack()

for root,dirs,filenames in os.walk(self.path):
    #iterate through the files
    num_files = len(filenames)
    i = 0
    for f in filenames:
        #if the file is a text file
        if ".txt" in f:
            #define the path of this new file as the datalog folder plus the filename
            file_path = os.path.join(self.path,f)
            #write the correct data to the csv file for this file
            self.addRows(f,file_path)
            i = i + 1
            out = str(i) + "/" + str(num_files) + " files processed"
            self.label3Text.set(out)

Ok - so the answer was that I needed to update my root window! 好的-答案是我需要更新我的根窗口! By calling window.update(), I solved the problem. 通过调用window.update(),我解决了这个问题。 Where window was declared as: window = Tk() 窗口声明为:window = Tk()

Just adding this in case someone else stumbles across this question. 只是添加这个,以防其他人偶然发现这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM