Reputation: 367
I'm retrofitting a GUI onto a CLI tool I made that manages screenshots. Whenever I run the file, no GUI appears despite triple-checking the code.
I've tried refactoring and looking for loops that never break, but I haven't found anything. I also compared my code to a few tutorials on Tkinter and haven't seen any problems.
Here's the code:
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()
I expect it to build a GUI when it runs, but nothing happens.
Upvotes: 0
Views: 341