Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Chapter 10 Assignment
- # Coffee Order
- # Logan McCarty
- from Tkinter import *
- class Application(Frame):
- """ GUI application that creates a burger based on user input. """
- def __init__(self, master):
- """ Initialize Frame. """
- Frame.__init__(self, master)
- self.grid()
- self.create_widgets()
- def create_widgets(self):
- """ Create widgets to get order information and to display order. """
- # create a welcome label
- Label(self,
- text = "Create your own Coffee"
- ).grid(row = 0, column = 0, sticky =W )
- # create a label and text entry for name of customer
- Label(self,
- text = "Name: "
- ).grid(row = 1, column = 0, sticky = W)
- self.ent_name = Entry(self)
- self.ent_name.grid(row = 1, column = 1, sticky = W)
- # create a label for topping check buttons
- Label(self,
- text = "Types of coffee:"
- ).grid(row = 2, column = 0, sticky = W)
- # create cheese check button
- self.has_cappuccino = BooleanVar()
- Checkbutton(self,
- text = "cappuccino ($2.00)",
- variable = self.has_cappuccino
- ).grid(row = 2, column = 1, sticky = W)
- # create lettuce check button
- self.has_expresso = BooleanVar()
- Checkbutton(self,
- text = "expresso ($2.25)",
- variable = self.has_expresso
- ).grid(row = 2, column = 2, sticky = W)
- # create onions check button
- self.has_latte = BooleanVar()
- Checkbutton(self,
- text = "latte ($1.75)",
- variable = self.has_latte
- ).grid(row = 2, column = 3, sticky = W)
- # create tomato check button
- self.has_icedlatte = BooleanVar()
- Checkbutton(self,
- text = "Iced Latte ($2.50)",
- variable = self.has_icedlatte
- ).grid(row = 2, column = 4, sticky = W)
- # create pickles check button
- self.has_icedcappuccino = BooleanVar()
- Checkbutton(self,
- text = "Iced Cappucino ($2.50)",
- variable = self.has_icedcappuccino
- ).grid(row = 3, column = 1, sticky = W)
- # create a label bun
- Label(self,
- text = "Takeout or takein:"
- ).grid(row = 4, column = 0, sticky = W)
- # create variable for single bun type
- self.take = StringVar()
- # create white radio button
- Radiobutton(self,
- text = "Takein",
- variable = self.take,
- value = "Takein"
- ).grid(row = 4, column = 1, sticky = W)
- # create wheat radio button
- Radiobutton(self,
- text = "Takeout",
- variable = self.take,
- value = "Takeout"
- ).grid(row = 4, column = 2, sticky = W)
- # create an order button
- Button(self,
- text = "Order",
- command = self.fill_order,
- ).grid(row = 5, column = 0, sticky = W)
- self.txt_order = Text(self, width = 75, height = 10, wrap = WORD)
- self.txt_order.grid(row = 6, column = 0, columnspan = 4)
- def fill_order(self):
- """ Fill text box with order based on user input. """
- # get values from the GUI
- name = self.ent_name.get()
- types = ""
- price = 0
- if self.has_cappuccino.get():
- types += "cappuccino, "
- price += pricing["cappuccino"]
- if self.has_expresso.get():
- types += "expresso, "
- price += pricing["expresso"]
- if self.has_latte.get():
- types += "latte, "
- price += pricing["latte"]
- if self.has_icedlatte.get():
- types += "iced latte, "
- price += pricing["iced latte"]
- if self.has_icedcappuccino.get():
- types += "iced cappucino, "
- price += pricing["iced cappucino"]
- if types == "":
- types = "no type of coffee selected "
- take = self.take.get()
- # create order
- order = name + " ordered a coffee with " + types + "and would like to " + take + ". " + "the total comes to $" + str(price)
- # display order
- self.txt_order.delete(0.0, END)
- self.txt_order.insert(0.0, order)
- pricing = {
- 'cappuccino': 2.00,
- 'expresso': 2.25,
- 'latte': 1.75,
- 'iced latte': 2.5,
- "iced cappucino": 2.50
- }
- def main():
- root = Tk()
- root.title("Order Up!")
- app = Application(root)
- root.mainloop()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement