I have encountered a problem I don't seem to understand.
video_path = "C:/Users/schwitzky/Downloads/Saul-goodman-3d nice res.mp4"
def open_customize_window():
customize_layout = [[sg.Text('Search for a custom alarm video: '), sg.Button('Search', key='CUSTOM_VIDEO_BUTTON')],
[sg.Text('Custom Video Alarm: '), sg.Text(video_path, key='CUSTOM_VIDEO_PATH')]]
customize_window = sg.Window('Customize Alarm', customize_layout, modal=True)
while True:
event, values = customize_window.read()
if event == 'CUSTOM_VIDEO_BUTTON':
video_path = filedialog.askopenfile()
video_path = video_path.name
customize_window['CUSTOM_VIDEO_PATH'].update(video_path)
As you can see in the above code, I have a global var video_path
defined outside the function. In my function, which opens a new window, the user can select a new .mp4 file to choose for his custom alarm. When that happens, I want to set the value of video_path
to that of the selected file.
But whenever I try to do that, Python doesn't seem to recognize my global var and instead thinks that the video_path
I reference inside sg.Text(video_path, key='CUSTOM_VIDEO_PATH')
is a new local variable.
How can I access the value of my global var inside the text element and set the value of my global var to the one chosen from the file dialog?