I'm using tkinter to create a GUI for an old script I have, but I'm stuck right now. I want to click a button to open the "Search File" window, choose a specific file and save its path in a variable. The code I have is able to open the window, then I can select the file and display it's path, but I couldn't find a way to save this path in a variable. This is what I have:
from tkinter import *
from tkinter import filedialog
def get_file_path():
# Open and return file path
file_path= filedialog.askopenfilename(title = "Select A File", filetypes = (("mov files", "*.png"), ("mp4", "*.mp4"), ("wmv", "*.wmv"), ("avi", "*.avi")))
l1 = Label(window, text = "File path: " + file_path).pack()
window = Tk()
# Creating a button to search the file
b1 = Button(window, text = "Open File", command = get_file_path).pack()
window.mainloop()
Does anyone know a good way to do this?