Here are some PyGUI versions of the ABC Challenge.

#---------------- Modal --------------------

from GUI import ModalDialog, Label, TextField, Row, Column, Grid
from GUI.StdButtons import DefaultButton, CancelButton
from GUI.Alerts import note_alert

a = TextField(width = 100)
b = TextField(width = 100)
c = TextField(width = 100)
buttons = Row([DefaultButton(), CancelButton()])
dlog = ModalDialog(title = "ABC Challenge")
dlog.add(Column([
    Grid([
        [Label("A"), a],
        [Label("B"), b],
        [Label("C"), c],
    ]),
    buttons],
    padding = (10, 10)))
dlog.shrink_wrap()
if dlog.present():
    note_alert("Sum = %s" % (int(a.text) + int(b.text) + int(c.text)))

#---------------- Non-Modal ------------------

from GUI import Window, Label, TextField, Grid, application

def update():
    try:
        c.text = str(int(a.text) + int(b.text))
    except ValueError:
        c.text = ""

a = TextField(width = 100, text_changed_action = update)
b = TextField(width = 100, text_changed_action = update)
c = TextField(width = 100, editable = False)
win = Window(title = "ABC Challenge")
win.add(
    Grid([
        [Label("A"), a],
        [Label("B"), b],
        [Label("A + B"), c],
    ], padding = (10, 10)))
win.shrink_wrap()
win.show()
application().run()

--
Greg
_______________________________________________
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