Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- root = Tk()
- s= Label( text="Our Ice Cream Shop",bg = 'Purple')
- s.pack(side = 'top')
- def quit(event=None):
- root.destroy()
- root.bind('<Escape>', quit)
- button = Button(text="Exit", command=quit)
- button.pack(side='bottom', fill='both')
- # -----------------------------------------------------------------------------
- # Create a frame within the main window.
- # -----------------------------------------------------------------------------
- frame = Frame(root)
- frame.pack(side='top')
- input_name = Label(frame, text="Please input your Name")
- input_name.pack(side='top')
- nameVar = StringVar()
- nameVar.set('Scene')
- name = Entry(frame,textvariable=nameVar, font='Verdana')
- name.pack()
- # Create a text box that explains the calculation.
- invitation = Label(frame, text="Please order below")
- invitation.pack(side='top')
- label = Label( text=" Choose Flavor type by scrolling up or down", bg='lightblue')
- label.pack()
- lb = Listbox(height =4)
- lb.pack(side = 'top')
- lb.insert(END,"Cookie Dough $2.50")
- lb.insert(END,"Mint $1.97")
- lb.insert(END,"Strawberry $1.99")
- lb.insert(END,"Chocolate $2.25")
- lb.insert(END,"Rocky Road $2.50")
- lb.insert(END,"Turtle $2.65")
- lb.insert(END,"Vanilla $1.75")
- number = Label(frame,text = 'Please input the Number of Ice-Creams', bg ='lightblue')
- number.pack(side = 'bottom')
- price = 0.0
- # Define an input variable and add an entry box so the user can change its value.
- number = StringVar()
- number.set('1')
- number_entry = Entry(frame, width=8, textvariable=number)
- number_entry.pack(side='left')
- # Define an output variable and a function to compute its value.
- total_price = StringVar()
- def calculate_price():
- global number, total_price,price
- items = lb.curselection()
- for item in items:
- if(item==0):
- price = 2.50
- elif(item ==1):
- price = 1.97
- elif(item ==2):
- price = 1.99
- # Get the string value of the x StringVar and convert it to a float.
- num_value = float(number.get())
- print(items)
- # Compute the floating point value of y.
- price_value = num_value * float(price)
- # Convert this to a formatted string, and store it in the y StringVar.
- total_price.set('%.2f' % price_value)
- print(total_price.get())
- def write_to_file(event =Button):
- user_name = nameVar.get()
- the_file = open("Reciept.txt", "w")
- the_file.write("First Name: " + user_name + "\n")
- the_file.write("Total:" + total_price.get())
- the_file.close()
- # Create a button to perform the calculation and pack it into the frame.
- compute = Button(frame, text=' BUY ', command= calculate_price)
- compute.pack(side='bottom')
- #compute.bind('<button>',calculate_price)
- # Create a text box that displays the value of the y StringVar.
- reciept = Button(frame, text=' Reciept ', command= write_to_file)
- reciept.pack(side='bottom')
- y_label = Label(frame, textvariable=total_price, width=8)
- y_label.pack(side='bottom')
- # -----------------------------------------------------------------------------
- # Activate the window.
- # -----------------------------------------------------------------------------
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement