From c905acdd3d955bbcf84c0c8a2afec184071ad9b6 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Fri, 7 Sep 2018 10:32:05 -0400 Subject: [PATCH] Demo Table Simulation - one way to make a table in PSG --- Demo_Table_Simulation.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Demo_Table_Simulation.py b/Demo_Table_Simulation.py index b61b263c..66f208c6 100644 --- a/Demo_Table_Simulation.py +++ b/Demo_Table_Simulation.py @@ -5,15 +5,32 @@ def TableSimulation(): Display data in a table format """ # sg.ChangeLookAndFeel('Dark') - - layout = [[sg.T('Table Using Combos and Input Elements', font='Any 18')]] + sg.SetOptions(element_padding=(0,0)) + layout = [[sg.T('Table Using Combos and Input Elements', font='Any 18')], + [sg.T('Row, Cal to change'), + sg.In(key='inputrow', justification='right', size=(8,1), pad=(1,1), do_not_clear=True), + sg.In(key='inputcol', size=(8,1), pad=(1,1), justification='right', do_not_clear=True), + sg.In(key='value', size=(8,1), pad=(1,1), justification='right', do_not_clear=True)]] for i in range(20): - inputs = [sg.In('{}{}'.format(i,j), size=(8, 1), pad=(1, 1), justification='right') for j in range(10)] + inputs = [sg.In('{}{}'.format(i,j), size=(8, 1), pad=(1, 1), justification='right', key=(i,j), do_not_clear=True) for j in range(10)] inputs = [sg.Combo(('Customer ID', 'Customer Name', 'Customer Info')), *inputs] layout.append(inputs) - sg.FlexForm('Table').LayoutAndRead(layout) + form = sg.FlexForm('Table', return_keyboard_events=True) + form.Layout(layout) + while True: + button, values = form.Read() + if button is None: + break + try: + location = (int(values['inputrow']), int(values['inputcol'])) + target_element = form.FindElement(location) + new_value = values['value'] + if target_element is not None and new_value != '': + target_element.Update(new_value) + except: + pass TableSimulation() \ No newline at end of file