So I am making a system to upload file for an AI project, so it will be both text files and image files. Is there a way to select files by dragging and dropping into a tkinter window, like how you can in GitHub? And is there a way to open a file browser window to select the files?
Asked
Active
Viewed 1,155 times
0
-
Look at this post: https://stackoverflow.com/questions/14267900/drag-and-drop-explorer-files-to-tkinter-entry-widget – The Pilot Dude Feb 09 '21 at 09:50
1 Answers
1
Yes. You can open a file browser window to select the files.
import tkinter as tk
from tkinter import filedialog
def getLocalFile():
root=tk.Tk()
root.withdraw()
filePath=filedialog.askopenfilename()
print('File path:',filePath)
return filePath
if __name__ == '__main__':
getLocalFile()

Himpq
- 36
- 3
-
Thank you so much! This is exactly what I meant when I said open a file browser window! – TheFlyingTechie Feb 10 '21 at 03:00
-
-
Yeah, cur=filedialog.askopenfilenames(filetypes=[('text files', '.txt'),('pythonfiles',('.py','.pyw'))]) – Himpq Feb 10 '21 at 13:29
-