Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. from tkinter import Tk,Scale,Label,Entry, Button, PhotoImage,HORIZONTAL,LEFT ,RIGHT, IntVar, StringVar
  2. from tkinter.messagebox import showinfo
  3.  
  4. class CateringCalcSlider(Tk):
  5.  
  6. def __init__(self,parent=None):
  7. super(CateringCalcSlider,self).__init__()
  8. self.title("Catering Calculator")
  9. self.geometry("250x200")
  10. self.cost_per_plate = IntVar()
  11. self.guests = IntVar()
  12. self.tip = IntVar()
  13. self.total_cost = StringVar()
  14. self.make_widgets()
  15.  
  16. def updateValues(self,event):
  17. cpp=self.cost_per_plate.get()
  18. guests=self.guests.get()
  19. tip_percent=self.tip.get()
  20. total_cost= self.total_cost()
  21. total_cost = cpp*guests
  22. tip=total_cost*(tip_percent/100)
  23. total_cost+=tip
  24. self.total_cost.set("${:,.2f}".format(total_cost))
  25.  
  26.  
  27. def make_widgets(self):
  28. Label(self, text="Catering Calculator").grid(row=0, column=1)
  29. Label(self, text="Cost Per Plate:").grid(row=1, column=0)
  30. Scale(self, from_=0, to=100, orient=HORIZONTAL, resolution=10, variable=self.cost_per_plate, command=lambda e:self.updateValues()).grid(row=1, column=1)
  31. Label(self, text="Guests:").grid(row=2, column=0)
  32. Scale(self, from_=0, to=100, orient=HORIZONTAL, variable=self.guests, command=lambda e: self.updateValues()).grid(row=2, column=1)
  33. Label(self, text="Tip:").grid(row=3, column=0)
  34. Scale(self, from_=0, to=25, orient=HORIZONTAL, resolution=5, variable=self.tip, command=lambda e: self.updateValues()).grid(row=3, column=1)
  35. Label(self, text="", textvariable=self.total_cost).grid(row=4, column=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement