2018-08-26 02:57:15 +00:00
|
|
|
import PySimpleGUI as g
|
|
|
|
|
|
|
|
# g.SetOptions(button_color=g.COLOR_SYSTEM_DEFAULT) # because some people like gray buttons
|
|
|
|
|
2018-08-26 14:45:52 +00:00
|
|
|
# Demonstrates a number of PySimpleGUI features including:
|
|
|
|
# Default element size
|
|
|
|
# auto_size_buttons
|
|
|
|
# ReadFormButton
|
|
|
|
# Dictionary return values
|
|
|
|
# Update of elements in form (Text, Input)
|
|
|
|
# do_not_clear of Input elements
|
|
|
|
|
|
|
|
|
2018-08-26 02:57:15 +00:00
|
|
|
# create the 2 Elements we want to control outside the form
|
|
|
|
out_elem = g.Text('', size=(15, 1), font=('Helvetica', 18), text_color='red')
|
|
|
|
in_elem = g.Input(size=(10,1), do_not_clear=True, key='input')
|
|
|
|
|
2018-08-26 14:45:52 +00:00
|
|
|
layout = [[g.Text('Choose Test'), g.DropDown(values=['Input', 'Output', 'Some option']), g.ReadFormButton('Input Option', auto_size_button=True)],
|
2018-08-26 02:57:15 +00:00
|
|
|
[in_elem],
|
2018-08-26 14:45:52 +00:00
|
|
|
[g.ReadFormButton('1'), g.ReadFormButton('2'), g.ReadFormButton('3')],
|
|
|
|
[g.ReadFormButton('4'), g.ReadFormButton('5'), g.ReadFormButton('6')],
|
|
|
|
[g.ReadFormButton('7'), g.ReadFormButton('8'), g.ReadFormButton('9')],
|
|
|
|
[g.ReadFormButton('Submit'),g.ReadFormButton('0'), g.ReadFormButton('Clear')],
|
2018-08-26 02:57:15 +00:00
|
|
|
[out_elem],
|
|
|
|
]
|
|
|
|
|
2018-08-26 14:45:52 +00:00
|
|
|
form = g.FlexForm('Keypad', default_element_size=(5,2), auto_size_buttons=False)
|
2018-08-26 02:57:15 +00:00
|
|
|
form.Layout(layout)
|
|
|
|
|
2018-08-26 14:45:52 +00:00
|
|
|
# Loop forever reading the form's values, updating the Input field
|
2018-08-26 02:57:15 +00:00
|
|
|
keys_entered = ''
|
|
|
|
while True:
|
|
|
|
button, values = form.Read() # read the form
|
|
|
|
if button is None: # if the X button clicked, just exit
|
|
|
|
break
|
|
|
|
if button == 'Clear': # clear keys if clear button
|
|
|
|
keys_entered = ''
|
|
|
|
elif button in '1234567890':
|
2018-08-26 14:45:52 +00:00
|
|
|
keys_entered = values['input'] # get what's been entered so far
|
2018-08-26 02:57:15 +00:00
|
|
|
keys_entered += button # add the new digit
|
|
|
|
elif button == 'Submit':
|
2018-08-26 14:45:52 +00:00
|
|
|
keys_entered = values['input']
|
2018-08-26 02:57:15 +00:00
|
|
|
out_elem.Update(keys_entered) # output the final string
|
|
|
|
|
|
|
|
in_elem.Update(keys_entered) # change the form to reflect current key string
|
|
|
|
|