From ddaf87914dec3b28898eca7534cee3c0ce5db1a3 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sun, 26 Aug 2018 10:45:52 -0400 Subject: [PATCH] Cleanup keypad demo --- Demo_Keypad.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Demo_Keypad.py b/Demo_Keypad.py index 3ca2afb4..124f34d0 100644 --- a/Demo_Keypad.py +++ b/Demo_Keypad.py @@ -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