#!/usr/local/bin/python ## # Checkbox # -------- # This program creates a window, two checkboxes and a quit button. # # It uses the checkbox call-back function choose_topping to set # a number called toppings to reflect the number of checkboxes # which have been checked. # # The ischecked function tells you whether a checkbox is currently # checked. Notice that each call-back gets passed as a parameter the # object which called the call-back. In the case of the quit function # this will be the quit button, in the case of choose_topping this # will be whichever checkbox the user clicked on. ## from graphapp import * def choose_topping(c): if (ischecked(c)): print "Oh, you want", gettext(c), "do you?" else: print "Don't want", gettext(c), "now, I see." def quit(b): exitapp() def main(): w = newwindow("Pizza", rect(0,0,200,150), StandardWindow) c1 = newcheckbox("Ham", rect(10,10,160,25), choose_topping) c2 = newcheckbox("Mushrooms", rect(10,40,160,25), choose_topping) b = newbutton("Quit", rect(10,80,80,30), quit) show(w) mainloop() main()