#!/usr/local/bin/python ## # Pizza Window Class # ------------------ # This program is an object-oriented pizza ordering program. # # It creates a window, several fields for typing in your name, # and several checkboxes and radio buttons for choosing what # you want on the pizza. Having filled in all the information, # a "place order" button will print out the order and exit the # the program. A "reset form" button empties the fields and # sets the program back to its inital state. ## from graphapp import * # Define the PizzaWindow class: class PizzaWindow: def __init__ (this): this.win = newwindow("Pizza", rect(0,0,400,450), StandardWindow) setbackground(this.win, LightBlue) r = rect(10,10,120,30) this.text1 = newlabel("Name:", r, AlignRight); r.x = r.x + 130 this.name = newfield("", r); r.y = r.y + 35 r.x = 10 this.text2 = newlabel("Phone:", r, AlignRight); r.x = r.x + 130 this.phone = newfield("", r); r.y = r.y + 35 r.x = 10 this.text3 = newlabel("Address:", r, AlignRight); r.x = r.x + 130 r.height = 75 this.address = newtextbox("", r); r.y = r.y + 80 r.height = 25 r.x = 10 r.y = r.y + 10 this.text4 = newlabel("Sauce:", r, AlignRight); r.x = r.x + 130 this.tomato = newradiobutton("Tomato", r, None); r.y = r.y + 35 this.barbeque = newradiobutton("BBQ", r, None); r.y = r.y + 35 check(this.tomato) r.x = 10 r.y = r.y + 10 this.text5 = newlabel("Toppings:", r, AlignRight); r.x = r.x + 130 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 r.x = 50 r.y = r.y + 10 this.order = newbutton("Order Pizza", r, this.place_order) r.x = r.x + 130 this.reset = newbutton("Reset Form", r, this.reset_form) show(this.win) def place_order(this, btn): print("Name = " + gettext(this.name)) print("Phone = " + gettext(this.phone)) print("Address = " + gettext(this.address)) print("Sauce:") if (ischecked(this.tomato)): print(" Tomato") if (ischecked(this.barbeque)): print(" Barbeque") 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 reset_form(this, btn): settext(this.name, "") settext(this.phone, "") settext(this.address, "") check(this.tomato) uncheck(this.barbeque) uncheck(this.ham) uncheck(this.mushrooms) uncheck(this.olives) uncheck(this.capsicum) show(this.name) # Define the main function: def main(): pizza_win = PizzaWindow() mainloop() main()