rescreva esse pedaço de codigo pra prencher key com a localizacao do arquivo escolhido…
- User
rescreva esse pedaço de codigo pra prencher key com a localizacao do arquivo escolhido pelo filebrowser: sg.theme('DarkBlue')
def btn(name): # a PySimpleGUI "User Defined Element" (see docs) return sg.Button(name, size=(6, 1), pad=(1, 1))
layout = [[sg.Input(default_text='Video URL or Local Path:', size=(30, 1), key='-VIDEO_LOCATION-'), sg.Button('load')], [sg.Image('', size=(300, 170), key='-VID_OUT-')], [btn('previous'), btn('play'), btn('next'), btn('pause'), btn('stop')], [sg.Text('Load media to start', key='-MESSAGE_AREA-')], [sg.Input(), sg.FileBrowse()]]
window = sg.Window('Mini Player', layout, element_justification='center', finalize=True, resizable=True)
window['-VID_OUT-'].expand(True, True)
- Assistant
Here's the modified code with the file browser filling the
keywith the selected file location:import PySimpleGUI as sg sg.theme('DarkBlue') def btn(name): # a PySimpleGUI "User Defined Element" (see docs) return sg.Button(name, size=(6, 1), pad=(1, 1)) layout = [ [sg.Input(default_text='Video URL or Local Path:', size=(30, 1), key='-VIDEO_LOCATION-'), sg.Button('load')], [sg.Image('', size=(300, 170), key='-VID_OUT-')], [btn('previous'), btn('play'), btn('next'), btn('pause'), btn('stop')], [sg.Text('Load media to start', key='-MESSAGE_AREA-')], [sg.Input(key='-FILE_LOCATION-'), sg.FileBrowse(target='-FILE_LOCATION-')] ] window = sg.Window('Mini Player', layout, element_justification='center', finalize=True, resizable=True) window['-VID_OUT-'].expand(True, True)I made the following changes:
- Added an
import PySimpleGUI as sgstatement at the beginning, as it was missing. - Added a
keyto thesg.Input()element in the last row of the layout:key='-FILE_LOCATION-'. - Added the
targetparameter to thesg.FileBrowse()element, targeting the input field with the key-FILE_LOCATION-:sg.FileBrowse(target='-FILE_LOCATION-').
Now, when a file is selected using the file browser, the input field with the key
-FILE_LOCATION-will be filled with the selected file's location. - Added an
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.