what my code basically does is copying .txt files from source_path to dest_path, you can test it without all the tkinter code to see that it works. Now, I wanted to make a GUI for this little script I created, and looking at tutorials they tell me that I have to write down root.mainloop() to create a window that stays.
What I want to do is (for now) have this little windows to be alongside my running script, but no matter where I put it it stops my running code and stays at the root.mainloop() forever.
I saw some people use root.after(), but it doesnt seems to work for me. How can I fix this?
import time, shutil, os, datetime
from tkinter import *
root = Tk() # defines tkinter
source_path = r"C:\SOURCE" # Your Source path
dest_path = r"C:\DESTINATION" # Destination path
file_ending = '.txt' # Needed File ending
files = os.listdir(source_path) # lits directorys in source_path
date = datetime.datetime.now().strftime('%d.%m.%Y') # get the current date
sleepingtime = 10 # amount of time sleeping
label = Label(root, text="some text")
while True:
label.pack()
root.mainloop()
print("Beginning checkup")
print("=================")
if not os.path.exists(source_path) or not os.path.exists(dest_path): # checks if directory exists
print("Destination/Source Path does not exist!")
else:
print("Destination exists, checking files...")
for f in files:
if f.endswith(file_ending):
new_path = os.path.join(dest_path, date + " - DO-PC")
src_path = os.path.join(source_path, f)
if not os.path.exists(new_path): # create the folders if they dont already exists
os.makedirs(new_path)
if not os.path.exists(os.path.join(new_path, f)):
print("copying " + src_path)
shutil.copy(src_path, new_path)
else:
print(src_path + " already copied")
print("=================")
print('Checkup done, waiting for next round...')
time.sleep(sleepingtime) # wait a few seconds between looking at the directory