簡體   English   中英

Tkinter GUI 不顯示任何內容

[英]Tkinter GUI not displaying anything

我正在將 GUI 改裝到我制作的用於管理屏幕截圖的 CLI 工具上。 每當我運行該文件時,盡管對代碼進行了三次檢查,但沒有出現任何 GUI。

我嘗試重構並尋找永不中斷的循環,但我沒有找到任何東西。 我還將我的代碼與 Tkinter 上的一些教程進行了比較,沒有發現任何問題。

這是代碼:

import os, time, shutil
from tkinter import *

class App:
    def __init__(self, root):
        self.root = root
        self.path_to_watch = "" # set to wherever your screenshots save by default
        self.new_dir = "" # set to where you want files moved to

        # create widgets
        path_box = Entry(root)
        path_box.pack()

        new_dir_box = Entry(root)
        new_dir_box.pack()

        # continuously fetch input
        while True:
            try:
                path_to_watch = path_box.get()
                new_dir = new_dir_box.get()
            except Exception:
                pass

        # create button that executes the clean
        b = Button(root, text="Clean", command=move_file())
        b.pack()

    def move_file(self):
        directory = os.listdir(path_to_watch)
        words = ['Screen','Shot','Screenshot'] # keywords for default OSX Screenshots

        for i in directory:
            src = path_to_watch + i
            new_dir_filename = new_dir + i 
            filename = i.split()
            for w in filename:
                if w in words:
                    if os.path.isdir(new_dir): 
                        shutil.move(src, new_dir_filename)
                        break
                    else:
                        os.mkdir(new_dir)
                        shutil.move(src, new_dir_filename)
                        break


if __name__ == '__main__':
    root = Tk()
    AppGUI = App(root)
    AppGUI.pack()
    root.mainloop()

我希望它在運行時構建一個 GUI,但沒有任何反應。

while True:循環沒有中斷。

暫無
暫無

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

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