from GUI import Window, Button, RadioButton, RadioGroup, application

labels = ["Banana", "Chocolate", "Strawberry"]

def report():
    value = grp.value
    try:
        print labels[value], "selected"
    except (TypeError, IndexError):
        print "Value =", value

def set_to_chocolate():
    grp.value = 1

win = Window(width = 250, title = "Radio Groups")

grp = RadioGroup(action = report)

y = 20
for i in xrange(0, 3):
    rbtn = RadioButton(
        position = (20, y), 
        title = labels[i],
        group = grp, 
        value = i)
    win.add(rbtn)
    y = rbtn.bottom + 5

pbtn = Button(title = "Set to Chocolate",
    position = (20, rbtn.bottom + 20),
    action = set_to_chocolate)
win.add(pbtn)

win.height = pbtn.bottom + 20
win.show()

instructions = """
There should be three radio buttons, "Banana", "Chocolate" and "Strawberry",
and a "Set to Chocolate" button. All radio buttons should initially be off.
Turning any of the buttons on should turn the others off. Changes to the
setting should be reported.
"""

print instructions

application().run()
