Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. from tkinter import *
  6.  
  7. root = Tk()
  8.  
  9. s= Label( text="Our Ice Cream Shop",bg = 'Purple')
  10. s.pack(side = 'top')
  11.  
  12.  
  13.  
  14. def quit(event=None):
  15. root.destroy()
  16.  
  17. root.bind('<Escape>', quit)
  18.  
  19.  
  20. button = Button(text="Exit", command=quit)
  21. button.pack(side='bottom', fill='both')
  22.  
  23. # -----------------------------------------------------------------------------
  24. # Create a frame within the main window.
  25. # -----------------------------------------------------------------------------
  26.  
  27. frame = Frame(root)
  28. frame.pack(side='top')
  29. input_name = Label(frame, text="Please input your Name")
  30. input_name.pack(side='top')
  31.  
  32. nameVar = StringVar()
  33. nameVar.set('Scene')
  34. name = Entry(frame,textvariable=nameVar, font='Verdana')
  35. name.pack()
  36.  
  37.  
  38. # Create a text box that explains the calculation.
  39. invitation = Label(frame, text="Please order below")
  40. invitation.pack(side='top')
  41.  
  42. label = Label( text=" Choose Flavor type by scrolling up or down", bg='lightblue')
  43. label.pack()
  44. lb = Listbox(height =4)
  45. lb.pack(side = 'top')
  46. lb.insert(END,"Cookie Dough $2.50")
  47. lb.insert(END,"Mint $1.97")
  48. lb.insert(END,"Strawberry $1.99")
  49. lb.insert(END,"Chocolate $2.25")
  50. lb.insert(END,"Rocky Road $2.50")
  51. lb.insert(END,"Turtle $2.65")
  52. lb.insert(END,"Vanilla $1.75")
  53.  
  54. number = Label(frame,text = 'Please input the Number of Ice-Creams', bg ='lightblue')
  55. number.pack(side = 'bottom')
  56.  
  57. price = 0.0
  58.  
  59.  
  60.  
  61. # Define an input variable and add an entry box so the user can change its value.
  62. number = StringVar()
  63. number.set('1')
  64. number_entry = Entry(frame, width=8, textvariable=number)
  65. number_entry.pack(side='left')
  66.  
  67. # Define an output variable and a function to compute its value.
  68. total_price = StringVar()
  69.  
  70. def calculate_price():
  71.  
  72.  
  73. global number, total_price,price
  74.  
  75. items = lb.curselection()
  76. for item in items:
  77. if(item==0):
  78. price = 2.50
  79. elif(item ==1):
  80. price = 1.97
  81. elif(item ==2):
  82. price = 1.99
  83.  
  84. # Get the string value of the x StringVar and convert it to a float.
  85. num_value = float(number.get())
  86. print(items)
  87. # Compute the floating point value of y.
  88. price_value = num_value * float(price)
  89.  
  90. # Convert this to a formatted string, and store it in the y StringVar.
  91. total_price.set('%.2f' % price_value)
  92. print(total_price.get())
  93. def write_to_file(event =Button):
  94. user_name = nameVar.get()
  95. the_file = open("Reciept.txt", "w")
  96. the_file.write("First Name: " + user_name + "\n")
  97. the_file.write("Total:" + total_price.get())
  98. the_file.close()
  99.  
  100.  
  101.  
  102. # Create a button to perform the calculation and pack it into the frame.
  103. compute = Button(frame, text=' BUY ', command= calculate_price)
  104. compute.pack(side='bottom')
  105. #compute.bind('<button>',calculate_price)
  106. # Create a text box that displays the value of the y StringVar.
  107. reciept = Button(frame, text=' Reciept ', command= write_to_file)
  108. reciept.pack(side='bottom')
  109.  
  110.  
  111. y_label = Label(frame, textvariable=total_price, width=8)
  112. y_label.pack(side='bottom')
  113.  
  114. # -----------------------------------------------------------------------------
  115. # Activate the window.
  116. # -----------------------------------------------------------------------------
  117. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement