1 | initial version |
To use Tkinter's filedialog to choose folders and files, you can follow these steps:
from tkinter import *
from tkinter import filedialog
root = Tk()
def open_file_dialog():
path = filedialog.askopenfilename() # to get files
# path = filedialog.askdirectory() # to get folders
print(path)
btn = Button(root, text="Open File Dialog", command=open_file_dialog)
btn.pack()
root.mainloop()
This will create a button called "Open File Dialog" and when you click on it, the file dialog box will open and allow you to choose the desired folder or file. The path of the selected folder or file will then be printed on the console.