-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathDemo_Button_Events_From_Browse.py
32 lines (22 loc) · 1.12 KB
/
Demo_Button_Events_From_Browse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import FreeSimpleGUI as sg
"""
Demo - Fill a listbox with list of files FilesBrowse button
This technique can be used to generate events from "Chooser Buttons" like FileBrowse, FilesBrowse
FolderBrowser, ColorChooserButton, Calendar Button
Any button that uses a "Target" can be used with an invisible Input Element to generate an
event when the user has made a choice. Enable events for the invisible element and an event will
be generated when the Chooser Button fills in the element
This particular demo users a list of chosen files to populate a listbox
"""
layout = [ [sg.LBox([], size=(20,10), key='-FILESLB-')],
[sg.Input(visible=False, enable_events=True, key='-IN-'), sg.FilesBrowse()],
[sg.Button('Go'), sg.Button('Exit')] ]
window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
# When choice has been made, then fill in the listbox with the choices
if event == '-IN-':
window['-FILESLB-'].Update(values['-IN-'].split(';'))
window.close()