I cant figure out how to store value from filedialog.askopenfilename. Now i saved the value to local variable but i want to work with this value later in other functions. I cant return the this value because i call function when i am creating the button. However i want to avoid using global variable. How can i do this? Is there some other way? Here is code:
from tkinter import Tk, StringVar, ttk
from tkinter import filedialog
from tkinter import messagebox
def browse_files():
filename = filedialog.askopenfilename(initialdir = "/",
title = "Select a File",
filetypes = (("Text files",
"*.txt*"),
("all files",
"*.*")))
print(filename)
root = Tk()
button1 = ttk.Button(root,text='Browse', command=browse_files)
button1.grid(row=0,column=0)