[Python-ideas] A GUI for beginners and experts alike

Mike Barnett mike_barnett at hotmail.com
Fri Aug 24 15:35:46 EDT 2018


So here's my alternative challenge:

Take two numbers as inputs. Add them together and display them in a third field. Whenever either input is changed, recalculate the output.

This requires proper event handling, so it's less likely to create a useless one-liner that has no bearing on real-world code.

------------------------------------



Sure thing... post yours. I'll go ahead and post mine first.

Here's the window this code produces.

https://user-images.githubusercontent.com/13696193/44604157-02a2ac00-a7b3-11e8-928b-f67c5f2b3961.jpg

And here's the code in a more readable form since the email formatting sucks.
https://user-images.githubusercontent.com/13696193/44604220-2cf46980-a7b3-11e8-86c5-ad3051222eaf.jpg

It's rather, uhm, simple to do....


import PySimpleGUI as gui

output = gui.Text('')

layout = [ [gui.Text('Enter 2 numbers')],
           [gui.Text('A'), gui.InputText()],
           [gui.Text('B'), gui.InputText()],
           [gui.Text('Answer = '), output],
           ]

form = gui.FlexForm('Realtime Updates', return_keyboard_events=True)
form.LayoutAndRead(layout)
while True:
    button, (a,b) = form.Read()
    try:
        answer = int(a) + int(b)
        output.Update(answer)
    except:
        pass


@mike


More information about the Python-ideas mailing list