I have seen many postings on the use of askopenfilename(), however I still can't seem to find anything to help me display the full file path in an entry box once I have selected said file. below I have included where I have left off.
from tkinter import *
from tkinter.filedialog import askopenfilenameglobal adef browse():a = askopenfilename(title='select new file')root = Tk()a = StringVar()l = Label(root, text="new file: ")
l.pack()e = Entry(root, width=25, textvariable=a)
e.pack()b = Button(root, text="Browse", command=browse)
b.pack()root.mainloop()
Inside your browse
function the local variable a does indeed contain the full path to your file. THe issue is that you have to call the StringVar's .set()
method, you can't just assign to the variable you bound to the StringVar. Replace a = askopenfilename(title='select new file')
with a.set(askopenfilename(title='select new file'))
and you will see the filename appear in the StringVar in your interface.
Please note that your program is not well-structured for a GUI interface task, but I presume at present your major difficulty is learning to use the primitives.