Python tkinter button return filepath Python 2.7.13 Python tkinter button return filepath Python 2.7.13 tkinter tkinter

Python tkinter button return filepath Python 2.7.13


Replace:

def browsefunc():    filename = filedialog.askopenfilename()    return filename

with:

filename = ''def browsefunc():    global filename    filename = filedialog.askopenfilename()

When a method can't return.


What you're doing here is saving the file name to a local variable and binding the function to a button. If you want to use that variable you can make a global variable where you can save the path whenever you choose a new one.