I was hoping anyone has any idea how I could use the askopenfile function in conjunction with an entry box(tkinter) so that the file path is displayed and can be edited in the entry box once selected using askopenfile. Any ideas on how to do this are welcomed thank you!
Asked
Active
Viewed 265 times
1 Answers
0
This would be done by making a small custom class for this widget
I have a widget I made for this specific reason:
from tkinter import *
from tkinter.filedialog import *
class FilePathFrame(Frame):
def __init__(self, master, *args, **kwargs):
super(FilePathFrame, self).__init__(master, *args, **kwargs)
def entry_set(entry, text):
entry.delete(0, 'end')
entry.insert(END, text)
item_label = Label(self, text="File Path: ", relief="flat", fg="gray40", anchor=W)
item_label.pack()
item_file = StringVar()
item_entry = Entry(self, textvariable=item_file)
item_entry.pack()
item_button = Button(self, text="\uD83D\uDCC2", relief="groove",
command=lambda: (
entry_set(item_entry, askopenfilename()), item_entry.configure(fg="black")))
item_button.pack()
window = Tk()
f = FilePathFrame(window)
f.pack()
window.mainloop()
Obviously you would need to work out how you want to display it, I just used the .pack()
method to display everything.

MatthewG
- 796
- 1
- 4
- 21
-
Thank you for helping me out, solitary hero:)! – Kevin M Dec 12 '19 at 19:18