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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-22 23:30:08 +0000
Seen: 15 times
Last updated: Jun 22 '23
How can I transfer .avi video files to Unity?
How to access HTML files stored on Google Drive?
What is the process for opening e57 files in C#?
Why are the files I uploaded not visible on the Windows Android Emulator?
How can I install Beegfs on Ubuntu 22.04?
How can a .zip file from GitHub be loaded into Google Colab?
What is the process of using the Multmerge() function in r to combine files in a directory?