Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import Tk,Scale,Label,Entry, Button, PhotoImage,HORIZONTAL,LEFT ,RIGHT, IntVar, StringVar
- from tkinter.messagebox import showinfo
- class CateringCalcSlider(Tk):
- def __init__(self,parent=None):
- super(CateringCalcSlider,self).__init__()
- self.title("Catering Calculator")
- self.geometry("250x200")
- self.cost_per_plate = IntVar()
- self.guests = IntVar()
- self.tip = IntVar()
- self.total_cost = StringVar()
- self.make_widgets()
- def updateValues(self,event):
- cpp=self.cost_per_plate.get()
- guests=self.guests.get()
- tip_percent=self.tip.get()
- total_cost= self.total_cost()
- total_cost = cpp*guests
- tip=total_cost*(tip_percent/100)
- total_cost+=tip
- self.total_cost.set("${:,.2f}".format(total_cost))
- def make_widgets(self):
- Label(self, text="Catering Calculator").grid(row=0, column=1)
- Label(self, text="Cost Per Plate:").grid(row=1, column=0)
- 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)
- Label(self, text="Guests:").grid(row=2, column=0)
- Scale(self, from_=0, to=100, orient=HORIZONTAL, variable=self.guests, command=lambda e: self.updateValues()).grid(row=2, column=1)
- Label(self, text="Tip:").grid(row=3, column=0)
- Scale(self, from_=0, to=25, orient=HORIZONTAL, resolution=5, variable=self.tip, command=lambda e: self.updateValues()).grid(row=3, column=1)
- Label(self, text="", textvariable=self.total_cost).grid(row=4, column=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement