Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. # Chapter 10 Assignment
  2. # Coffee Order
  3. # Logan McCarty
  4. from Tkinter import *
  5.  
  6. class Application(Frame):
  7. """ GUI application that creates a burger based on user input. """
  8. def __init__(self, master):
  9. """ Initialize Frame. """
  10. Frame.__init__(self, master)
  11. self.grid()
  12. self.create_widgets()
  13.  
  14. def create_widgets(self):
  15. """ Create widgets to get order information and to display order. """
  16. # create a welcome label
  17. Label(self,
  18. text = "Create your own Coffee"
  19. ).grid(row = 0, column = 0, sticky =W )
  20.  
  21. # create a label and text entry for name of customer
  22. Label(self,
  23. text = "Name: "
  24. ).grid(row = 1, column = 0, sticky = W)
  25. self.ent_name = Entry(self)
  26. self.ent_name.grid(row = 1, column = 1, sticky = W)
  27.  
  28. # create a label for topping check buttons
  29. Label(self,
  30. text = "Types of coffee:"
  31. ).grid(row = 2, column = 0, sticky = W)
  32.  
  33. # create cheese check button
  34. self.has_cappuccino = BooleanVar()
  35. Checkbutton(self,
  36. text = "cappuccino ($2.00)",
  37. variable = self.has_cappuccino
  38. ).grid(row = 2, column = 1, sticky = W)
  39.  
  40. # create lettuce check button
  41. self.has_expresso = BooleanVar()
  42. Checkbutton(self,
  43. text = "expresso ($2.25)",
  44. variable = self.has_expresso
  45. ).grid(row = 2, column = 2, sticky = W)
  46.  
  47. # create onions check button
  48. self.has_latte = BooleanVar()
  49. Checkbutton(self,
  50. text = "latte ($1.75)",
  51. variable = self.has_latte
  52. ).grid(row = 2, column = 3, sticky = W)
  53.  
  54. # create tomato check button
  55. self.has_icedlatte = BooleanVar()
  56. Checkbutton(self,
  57. text = "Iced Latte ($2.50)",
  58. variable = self.has_icedlatte
  59. ).grid(row = 2, column = 4, sticky = W)
  60.  
  61. # create pickles check button
  62. self.has_icedcappuccino = BooleanVar()
  63. Checkbutton(self,
  64. text = "Iced Cappucino ($2.50)",
  65. variable = self.has_icedcappuccino
  66. ).grid(row = 3, column = 1, sticky = W)
  67.  
  68. # create a label bun
  69. Label(self,
  70. text = "Takeout or takein:"
  71. ).grid(row = 4, column = 0, sticky = W)
  72.  
  73. # create variable for single bun type
  74. self.take = StringVar()
  75.  
  76. # create white radio button
  77. Radiobutton(self,
  78. text = "Takein",
  79. variable = self.take,
  80. value = "Takein"
  81. ).grid(row = 4, column = 1, sticky = W)
  82.  
  83. # create wheat radio button
  84. Radiobutton(self,
  85. text = "Takeout",
  86. variable = self.take,
  87. value = "Takeout"
  88. ).grid(row = 4, column = 2, sticky = W)
  89.  
  90. # create an order button
  91. Button(self,
  92. text = "Order",
  93. command = self.fill_order,
  94. ).grid(row = 5, column = 0, sticky = W)
  95.  
  96. self.txt_order = Text(self, width = 75, height = 10, wrap = WORD)
  97. self.txt_order.grid(row = 6, column = 0, columnspan = 4)
  98.  
  99. def fill_order(self):
  100. """ Fill text box with order based on user input. """
  101. # get values from the GUI
  102. name = self.ent_name.get()
  103. types = ""
  104. price = 0
  105. if self.has_cappuccino.get():
  106. types += "cappuccino, "
  107. price += pricing["cappuccino"]
  108. if self.has_expresso.get():
  109. types += "expresso, "
  110. price += pricing["expresso"]
  111. if self.has_latte.get():
  112. types += "latte, "
  113. price += pricing["latte"]
  114. if self.has_icedlatte.get():
  115. types += "iced latte, "
  116. price += pricing["iced latte"]
  117. if self.has_icedcappuccino.get():
  118. types += "iced cappucino, "
  119. price += pricing["iced cappucino"]
  120. if types == "":
  121. types = "no type of coffee selected "
  122. take = self.take.get()
  123.  
  124. # create order
  125. order = name + " ordered a coffee with " + types + "and would like to " + take + ". " + "the total comes to $" + str(price)
  126.  
  127. # display order
  128. self.txt_order.delete(0.0, END)
  129. self.txt_order.insert(0.0, order)
  130.  
  131. pricing = {
  132. 'cappuccino': 2.00,
  133. 'expresso': 2.25,
  134. 'latte': 1.75,
  135. 'iced latte': 2.5,
  136. "iced cappucino": 2.50
  137. }
  138.  
  139. def main():
  140. root = Tk()
  141. root.title("Order Up!")
  142. app = Application(root)
  143. root.mainloop()
  144.  
  145. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement