Merge pull request #2544 from PySimpleGUI/Dev-latest

New Demo showing using invisble input elements as target
This commit is contained in:
PySimpleGUI 2020-01-27 06:19:53 -05:00 committed by GitHub
commit 0c6bc9784c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
import PySimpleGUI 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 (None, '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()