#!/usr/local/bin/python ## # Checkbox 2 # ---------- # This program creates a window, four checkboxes and a button. # # Unlike checkbox.c, this program makes the checkboxes global # variables, and uses ischecked to decide which ones have been # switched on by the user. # # Notice the checkboxes have no callbacks. The work is done # inside the button's call-back place_order, which also exits # the program using exitapp. ## from graphapp import * class CheckboxTest: def place_order(this, b): print "Toppings:" if (ischecked(this.ham)): print " Ham" if (ischecked(this.mushrooms)): print " Mushrooms" if (ischecked(this.olives)): print " Olives" if (ischecked(this.capsicum)): print " Capsicum" exitapp() def __init__ (this): this.win = newwindow("Pizza", rect(0,0,200,230), StandardWindow) r = rect(10,10,120,30) this.ham = newcheckbox("Ham", r, None); r.y = r.y + 35 this.mushrooms = newcheckbox("Mushrooms", r, None); r.y = r.y + 35 this.olives = newcheckbox("Olives", r, None); r.y = r.y + 35 this.capsicum = newcheckbox("Capsicum", r, None); r.y = r.y + 35 this.order_it = newbutton("Order Pizza", r, this.place_order) show(this.win) def main(): test = CheckboxTest() mainloop() main()