How Could I Go Upon Implementing Tkinter.filedialog.askdirectory() Into This?
I'm trying to make it so in this simple gui, you can change the directory, for the source file and the destination file. From an earlier post, I saw I could use tkinter.filedialop.
Solution 1:
The simplest way to solve this problem was to just implement, filedialog.askdirectory(), where it would replace the path I put for source and target directory.
Like this:
import shutil
import os
import tkinter as tk
source_dir = filedialog.askdirectory()
target_dir = filedialog.askdirectory()
file_names = os.listdir(source_dir)
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.create_widgets()
def create_widgets(self):
self.testhi = tk.Button(self)
self.testhi["text"] = "Move!"
self.testhi["command"] = self.movefiles
self.testhi.pack(side="top")
self.quit = tk.Button(self, text="QUIT", fg="red",
command=self.master.destroy)
self.quit.pack(side="bottom")
def movefiles(self):
for file_name in file_names:
shutil.move(os.path.join(source_dir, file_name), target_dir) #for file_name in file_names: #shutil.move(os.path.join(source_dir, file_name), target_dir)
root = tk.Tk()
app = Application(master=root)
app.mainloop()
Post a Comment for "How Could I Go Upon Implementing Tkinter.filedialog.askdirectory() Into This?"