Вы можете объявить file_path
как глобальную переменную в get_file_path
def get_file_path():
global 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()
Затем вы можете получить доступ к этой переменной из любого места в скрипте
------ Edit- ----- Согласно тому, что вы сказали в своем комментарии, я говорю, что вы можете использовать tkinter.StringVar
, чтобы сохранить путь к файлу, а затем получить к нему доступ позже при вызове count_frames
в качестве аргумента.
It может быть реализовано следующим образом:
from tkinter import *
from tkinter import filedialog
file_path_var = StringVar()
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")))
file_path_var.set(file_path) #setting the variable to the value from file path
#Now the file_path can be acessed from inside the function and outside
file_path_var.get() # will return the value stored in file_path_var
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()
# will also return the value saved in file_path_var
file_path_var.get()
window.mainloop()
print(file_path)
Так что теперь, где бы ни была ваша функция count_frames
, до тех пор, пока вы сначала выбрали файл, вы можете просто выполнить
count_frames(file_path_var.get())