I need to save the file path returned by askopenfilename
within tkinter filedialog
for later use I trigger the function openFile
via a button which I define and I expect this function to store the requested file's path, I tried using global variable and StringVar() too but It didn't work it gives empty string, the global variable path
is where I need file path string.
code :
from tkinter import *
from PIL import ImageTk, Image
import cv2
from matplotlib.pyplot import text
# from Main import pipeline
# import Object_Detection
# from Object_Detection import Simulation
from tkinter import filedialog
root = Tk()
# Create a frame
app = Frame(root, bg="white")
app.grid()
# Create a label in the frame
lmain = Label(app)
lmain.grid()
path = StringVar()
def openFile():
file_path = filedialog.askopenfilename()
path.set(file_path)
button = Button(text="Open a video file",command=openFile)
button.grid()
print(path.get())
cap = cv2.VideoCapture('.\\Datasets\\video_datasets\\drive0.mp4')
# det = Object_Detection.ObjectDetection()
# function for video streaming
def video_stream():
_, frame = cap.read()
# image_box,classes,scores,boxes = pipeline(frame,det)
# Simulation().DistanceEstimation(boxes,classes,scores,image_box)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(1, video_stream)
video_stream()
root.mainloop()