2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-02 17:38:59 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
|
|
|
Example of GUI
|
|
|
|
'''
|
|
|
|
|
|
|
|
def main():
|
|
|
|
sg.change_look_and_feel('TanBlue')
|
2018-09-04 17:40:31 +00:00
|
|
|
|
|
|
|
column1 = [
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.Text('Column 1', background_color=sg.DEFAULT_BACKGROUND_COLOR,
|
|
|
|
justification='center', size=(10, 1))],
|
|
|
|
[sg.Spin(values=('Spin Box 1', '2', '3'),
|
|
|
|
initial_value='Spin Box 1', key='spin1')],
|
|
|
|
[sg.Spin(values=('Spin Box 1', '2', '3'),
|
|
|
|
initial_value='Spin Box 2', key='spin2')],
|
2018-09-04 17:40:31 +00:00
|
|
|
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3', key='spin3')]]
|
2018-09-02 17:38:59 +00:00
|
|
|
|
|
|
|
layout = [
|
|
|
|
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
|
|
|
[sg.Text('Here is some text.... and a place to enter text')],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.InputText('This is my text', key='in1')],
|
|
|
|
[sg.CBox('Checkbox', key='cb1'), sg.CBox(
|
|
|
|
'My second checkbox!', key='cb2', default=True)],
|
2018-09-04 17:40:31 +00:00
|
|
|
[sg.Radio('My first Radio! ', "RADIO1", key='rad1', default=True),
|
|
|
|
sg.Radio('My second Radio!', "RADIO1", key='rad2')],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.MLine(default_text='This is the default Text should you decide not to type anything', size=(35, 3),
|
|
|
|
key='multi1'),
|
|
|
|
sg.MLine(default_text='A second multi-line', size=(35, 3), key='multi2')],
|
|
|
|
[sg.Combo(('Combobox 1', 'Combobox 2'), key='combo', size=(20, 1)),
|
2018-09-04 17:40:31 +00:00
|
|
|
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), key='slide1', default_value=85)],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.OptionMenu(('Menu Option 1', 'Menu Option 2',
|
|
|
|
'Menu Option 3'), key='optionmenu')],
|
2018-09-04 17:40:31 +00:00
|
|
|
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3), key='listbox'),
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.Slider(range=(1, 100),
|
|
|
|
orientation='v',
|
|
|
|
size=(5, 20),
|
|
|
|
default_value=25, key='slide2', ),
|
|
|
|
sg.Slider(range=(1, 100),
|
|
|
|
orientation='v',
|
|
|
|
size=(5, 20),
|
|
|
|
default_value=75, key='slide3', ),
|
|
|
|
sg.Slider(range=(1, 100),
|
|
|
|
orientation='v',
|
|
|
|
size=(5, 20),
|
|
|
|
default_value=10, key='slide4'),
|
|
|
|
sg.Col(column1, background_color='gray34')],
|
2018-09-02 17:38:59 +00:00
|
|
|
[sg.Text('_' * 80)],
|
|
|
|
[sg.Text('Choose A Folder', size=(35, 1))],
|
2019-10-23 20:10:03 +00:00
|
|
|
[sg.Text('Your Folder', size=(15, 1), justification='right'),
|
|
|
|
sg.InputText('Default Folder', key='folder'), sg.FolderBrowse()],
|
2019-09-20 20:59:15 +00:00
|
|
|
[sg.Button('Exit'),
|
|
|
|
sg.Text(' ' * 40), sg.Button('SaveSettings'), sg.Button('LoadSettings')]
|
2018-09-02 17:38:59 +00:00
|
|
|
]
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('Form Fill Demonstration', layout, default_element_size=(40, 1), grab_anywhere=False)
|
2018-09-02 17:38:59 +00:00
|
|
|
|
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2018-09-04 17:40:31 +00:00
|
|
|
|
2019-06-26 15:09:42 +00:00
|
|
|
if event == 'SaveSettings':
|
2019-10-23 20:10:03 +00:00
|
|
|
filename = sg.popup_get_file('Save Settings', save_as=True, no_window=True)
|
2018-09-24 22:01:00 +00:00
|
|
|
window.SaveToDisk(filename)
|
2018-09-05 03:13:15 +00:00
|
|
|
# save(values)
|
2019-06-26 15:09:42 +00:00
|
|
|
elif event == 'LoadSettings':
|
2019-10-23 20:10:03 +00:00
|
|
|
filename = sg.popup_get_file('Load Settings', no_window=True)
|
2018-09-24 22:01:00 +00:00
|
|
|
window.LoadFromDisk(filename)
|
2018-09-05 03:13:15 +00:00
|
|
|
# load(form)
|
2019-06-26 15:09:42 +00:00
|
|
|
elif event in ('Exit', None):
|
2018-09-02 17:38:59 +00:00
|
|
|
break
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|
2018-09-04 17:40:31 +00:00
|
|
|
|
2018-09-02 17:38:59 +00:00
|
|
|
|
2018-09-04 17:40:31 +00:00
|
|
|
if __name__ == '__main__':
|
2019-10-23 20:10:03 +00:00
|
|
|
main()
|