簡體   English   中英

有什么方法可以刷新/更新 tkinter 中的頂層 window?

[英]Is there any way to refresh/update toplevel window in tkinter?

我正在頂層 window 上創建檢查按鈕,這些檢查按鈕適用於存儲在緩存文件夾中的所有文件,但是當緩存文件夾中的文件添加或刪除時,檢查按鈕沒有更新是否有任何方法可以刷新或更新頂層window 不關閉它。 '''

class encrypt_files:
            def __init__(self):
                pass
            def encrypt_file(self):
                paths =  filedialog.askopenfilenames()
                for item in paths:
                    # encryption/decryption buffer size - 64K
                    bufferSize = 64 * 1024
                    password = "FootWork"
                    # adding encrypted files to cache folder
                    pyAesCrypt.encryptFile(item,path.basename(item) + ".aes", password, bufferSize)
        class encrypt_folder:
            def __init__(self):
                pass
            def open_folder(self):
       #creating top level window
                top_level = tk.Toplevel()
                top_level.geometry("700x500+500+200")
                top_level.title("Encyption Files")
                p2 = encrypt_files()

        
                tool_bar = ttk.LabelFrame(top_level)
                tool_bar.pack(side = "top",fill = "both")
                
                main_body = ttk.LabelFrame(top_level)
                main_body.pack(side = "top",fill = "both")
                
                upload_button = ttk.Button(tool_bar,text = "Upload file",command = lambda :p2.encrypt_file())
                upload_button.grid(row = 0,column = 0)
        
        #checking for files in cache folder
                if "cache" not in os.getcwd().split(r"\ ".replace(" ", "")):
                    os.chdir(os.getcwd() + r"\cache")
                dirlist  = os.listdir()
                radiolist = {}

        #placing all check buttons on toplevel window which i want to update
                for i in dirlist:
                    radiolist[i] = tk.IntVar()
                    check_button = ttk.Checkbutton(main_body,text = i,variable = radiolist[i])
                    check_button.grid(sticky="w")
        
                top_level.mainloop()

'''

沒有內置的東西可以做到這一點。 您必須編寫一個 function 來迭代文件和/或檢查按鈕並適當地更新它們。 Tkinter 為您提供添加或刪除復選按鈕、更改其 state 以及更改其標簽所需的所有工具。

所有這些都可以在不關閉 window 的情況下完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM