【问题标题】:Tkinter GUI not displaying anythingTkinter GUI 不显示任何内容
【发布时间】:2020-02-02 01:50:41
【问题描述】:

我正在将 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,但没有任何反应。

【问题讨论】:

  • AppGUI.pack()? AppGUI 没有 pack 方法。
  • command=move_file()
  • @Aran-Fey “罪魁祸首”是什么意思?
  • @Aran-Fey 我根据重复修复了它,没有用,然后删除按钮仍然存在同样的问题。
  • 啊,还有while True:循环。

标签: python tkinter tk


【解决方案1】:

while True: 循环没有中断。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2017-08-19
    • 2016-01-05
    • 2011-12-22
    • 1970-01-01
    相关资源
    最近更新 更多