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
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to