#!/usr/local/bin/python ## # Pizza # ----- # This program is a 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 * # Global variables: name = None # Text fields phone = None address = None ham = None # Toppings mushrooms = None olives = None capsicum = None tomato = None # Sauces barbeque = None order = None # Order Pizza button reset = None # Reset form button # Functions: def place_order(b): global name, phone, address global ham, mushrooms, olives, capsicum, tomato, barbeque print("Name = " + gettext(name)) print("Phone = " + gettext(phone)) print("Address = " + gettext(address)) print("Sauce:") if (ischecked(tomato)): print(" Tomato") if (ischecked(barbeque)): print(" Barbeque") print("Toppings:") if (ischecked(ham)): print(" Ham") if (ischecked(mushrooms)): print(" Mushrooms") if (ischecked(olives)): print(" Olives") if (ischecked(capsicum)): print(" Capsicum") exitapp() def reset_form(bb): global name, phone, address global ham, mushrooms, olives, capsicum, tomato, barbeque settext(name, "") settext(phone, "") settext(address, "") check(tomato) uncheck(barbeque) uncheck(ham) uncheck(mushrooms) uncheck(olives) uncheck(capsicum) show(name) def main(): global name, phone, address global ham, mushrooms, olives, capsicum, tomato, barbeque w = newwindow("Pizza", rect(0,0,400,450), StandardWindow) setbackground(w, LightBlue) r = rect(10,10,120,30) L1 = newlabel("Name:", r, AlignRight); r.x = r.x + 130 name = newfield("", r); r.y = r.y + 35 r.x = 10 L2 = newlabel("Phone:", r, AlignRight); r.x = r.x + 130 phone = newfield("", r); r.y = r.y + 35 r.x = 10 L3 = newlabel("Address:", r, AlignRight); r.x = r.x + 130 r.height = 75 address = newtextbox("", r); r.y = r.y + 80 r.height = 25 r.x = 10 r.y = r.y + 10 L4 = newlabel("Sauce:", r, AlignRight); r.x = r.x + 130 tomato = newradiobutton("Tomato", r, None); r.y = r.y + 35 barbeque = newradiobutton("BBQ", r, None); r.y = r.y + 35 check(tomato) r.x = 10 r.y = r.y + 10 L5 = newlabel("Toppings:", r, AlignRight); r.x = r.x + 130 ham = newcheckbox("Ham", r, None); r.y = r.y + 35 mushrooms = newcheckbox("Mushrooms", r, None); r.y = r.y + 35 olives = newcheckbox("Olives", r, None); r.y = r.y + 35 capsicum = newcheckbox("Capsicum", r, None); r.y = r.y + 35 r.x = 50 r.y = r.y + 10 order = newbutton("Order Pizza", r, place_order); r.x = r.x + 130 reset = newbutton("Reset Form", r, reset_form) show(w) mainloop() main()