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-11 14:09:48 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
|
|
|
Usage of Disable elements
|
|
|
|
'''
|
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Dark')
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.set_options(element_padding=(0, 0))
|
2018-09-24 22:01:00 +00:00
|
|
|
|
2018-09-11 14:09:48 +00:00
|
|
|
layout = [
|
2019-10-23 20:10:03 +00:00
|
|
|
[ sg.Text('Notes:', pad=((3, 0), 0)),
|
|
|
|
sg.Input(size=(44, 1), background_color='white', text_color='black', key='notes')],
|
|
|
|
|
|
|
|
[ sg.Text('Output:', pad=((3, 0), 0)),
|
|
|
|
sg.Text('', size=(44, 1), text_color='white', key='output')],
|
|
|
|
|
|
|
|
[sg.CBox('Checkbox:', default=True, pad=((3, 0), 0), disabled=True, key='cbox'),
|
|
|
|
sg.Listbox((1, 2, 3, 4), size=(8, 3), disabled=True, key='listbox'),
|
|
|
|
sg.Radio('Radio 1', default=True, group_id='1', disabled=True, key='radio1'),
|
|
|
|
sg.Radio('Radio 2', default=False, group_id='1', disabled=True, key='radio2')],
|
|
|
|
|
|
|
|
[sg.Spin((1, 2, 3, 4), 1, disabled=True, key='spin'),
|
|
|
|
sg.OptionMenu((1, 2, 3, 4), disabled=True, key='option'),
|
|
|
|
sg.Combo(values=(1, 2, 3, 4), disabled=True, key='combo')],
|
|
|
|
|
|
|
|
[sg.ML('Multiline', size=(20, 3), disabled=True, key='multi')],
|
|
|
|
|
|
|
|
[sg.Slider((1, 10), size=(20, 20), orientation='h', disabled=True, key='slider')],
|
|
|
|
|
|
|
|
[sg.Button('Enable', button_color=('white', 'black')),
|
|
|
|
sg.Button('Disable', button_color=('white', 'black')),
|
|
|
|
sg.Button('Reset', button_color=('white', '#9B0023'), key='reset'),
|
|
|
|
sg.Button('Values', button_color=('white', 'springgreen4')),
|
|
|
|
sg.Button('Exit', disabled=True, button_color=('white', '#00406B'), key='exit')]]
|
|
|
|
|
|
|
|
window = sg.Window("Disable Elements Demo", layout,
|
|
|
|
default_element_size=(12, 1),
|
|
|
|
text_justification='r',
|
|
|
|
auto_size_text=False,
|
|
|
|
auto_size_buttons=False,
|
|
|
|
keep_on_top=True,
|
|
|
|
grab_anywhere=False,
|
|
|
|
default_button_element_size=(12, 1),
|
|
|
|
finalize=True)
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2018-10-15 20:07:23 +00:00
|
|
|
key_list = 'cbox', 'listbox', 'radio1', 'radio2', 'spin', 'option', 'combo', 'reset', 'notes', 'multi', 'slider', 'exit'
|
2018-09-24 22:01:00 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# don't do this kind of for-loop
|
|
|
|
for key in key_list:
|
|
|
|
window[key].update(disabled=True)
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2018-09-11 14:09:48 +00:00
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'exit'):
|
2018-09-11 14:09:48 +00:00
|
|
|
break
|
2018-10-15 20:07:23 +00:00
|
|
|
elif event == 'Disable':
|
2019-10-23 20:10:03 +00:00
|
|
|
for key in key_list:
|
|
|
|
window[key].update(disabled=True)
|
2018-10-15 20:07:23 +00:00
|
|
|
elif event == 'Enable':
|
2019-10-23 20:10:03 +00:00
|
|
|
for key in key_list:
|
|
|
|
window[key].update(disabled=False)
|
2018-10-15 20:07:23 +00:00
|
|
|
elif event == 'Values':
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.popup(values, keep_on_top=True)
|
2018-09-11 14:09:48 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|