Cleanup keypad demo

This commit is contained in:
MikeTheWatchGuy 2018-08-26 10:45:52 -04:00
parent 07772cb2e7
commit ddaf87914d
1 changed files with 18 additions and 8 deletions

View File

@ -2,22 +2,32 @@ import PySimpleGUI as g
# g.SetOptions(button_color=g.COLOR_SYSTEM_DEFAULT) # because some people like gray buttons
# 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
# 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')
layout = [[g.Text('Choose Test'), g.DropDown(values=['Input', 'Output', 'Some option']), g.ReadFormButton('Input Option', size=(10,1))],
layout = [[g.Text('Choose Test'), g.DropDown(values=['Input', 'Output', 'Some option']), g.ReadFormButton('Input Option', auto_size_button=True)],
[in_elem],
[g.ReadFormButton('1', size=(5,2)), g.ReadFormButton('2', size=(5,2)), g.ReadFormButton('3', size=(5,2))],
[g.ReadFormButton('4', size=(5,2)), g.ReadFormButton('5', size=(5,2)), g.ReadFormButton('6', size=(5,2))],
[g.ReadFormButton('7', size=(5,2)), g.ReadFormButton('8', size=(5,2)), g.ReadFormButton('9', size=(5,2))],
[g.ReadFormButton('Submit', size=(5,2)),g.ReadFormButton('0', size=(5,2)), g.ReadFormButton('Clear', size=(5,2))],
[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')],
[out_elem],
]
form = g.FlexForm('Keypad', auto_size_buttons=False)
form = g.FlexForm('Keypad', default_element_size=(5,2), auto_size_buttons=False)
form.Layout(layout)
# Loop forever reading the form's values, updating the Input field
keys_entered = ''
while True:
button, values = form.Read() # read the form
@ -26,10 +36,10 @@ while True:
if button == 'Clear': # clear keys if clear button
keys_entered = ''
elif button in '1234567890':
keys_entered = values['input'] # get what's been entered so far
keys_entered = values['input'] # get what's been entered so far
keys_entered += button # add the new digit
elif button == 'Submit':
keys_entered = in_elem.Get()
keys_entered = values['input']
out_elem.Update(keys_entered) # output the final string
in_elem.Update(keys_entered) # change the form to reflect current key string