0

I am trying to get a Tkinter listbox to populate with an unknown filename that a user imports with a browse button. I am able to populate the listbox with "File has been uploaded" everytime a file is selected, although I want the filename(or path) to be displayed in the listbox. Here is what I have so far:

def browse():
openFile = filedialog.askopenfile(initialdir = '/', title="Select a File")
fileList.insert('end', "File has been uploaded")
return

browseButton = tk.Button(root, text="Browse", width=15, padx=10, pady=10, command=browse)
browseButton.grid(row=0, column=0)

fileList = tk.Listbox(root, height=15, width=50)
fileList.grid(row=2, column=0, columnspan=3)
tturgeon
  • 1
  • 1
  • Simply call `fileList.insert('end', openFile.name)`. If you only want the file path, use `filedialog.askopenfilename(...)` instead. `filedialog.askopenfile(...)` will open the file right after the file is selected and confirmed. – acw1668 Apr 20 '20 at 16:10
  • That worked! Thanks for the response. – tturgeon Apr 20 '20 at 16:22

0 Answers0