I would like to make a browse folder button using tkinter and to store the path into a variable. So far i am able to print the path but i am not able to store it in a variable. Can you please advise?
Below i attach the code that i use.
from tkinter import filedialog
from tkinter import *
def browse_button():
filename = filedialog.askdirectory()
print(filename)
return filename
root = Tk()
v = StringVar()
button2 = Button(text="Browse", command=browse_button).grid(row=0, column=3)
mainloop()
filename
. If you wish to store for other functions to use, then you should use a. Classes b. Global variables. I'll provide an example of a Global variable below.