Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- # -- Def / commands -- #
- a = "€" # money sign
- cart_holder = [] # to hold items
- money_holder = [] # to hold money
- # - Menu - #
- def remove():
- global Entry_to_remove_stuff,c,g,p,q,money_cart,number
- print ("Function started")
- product_name = (Entry_to_remove_stuff.get()).title()
- print ("Product to remove {name_remove}".format(name_remove = product_name))
- try:
- if product_name == "Pie":
- number = int(4)
- elif product_name == "Cake":
- number = int(7)
- elif product_name == "Chainsaw":
- number = int(20)
- elif product_name == "Hammer":
- number = int(210)
- elif product_name == "Beer":
- number = int(1)
- elif product_name == "Paper":
- number = int(2)
- elif product_name == "Cookies":
- number = int(2)
- elif product_name == "Scissors":
- number = int(4)
- elif product_name == "Socks":
- number = int(2)
- elif product_name == "Tape":
- number = int (5)
- elif product_name == "Lamp":
- number = int(25)
- elif product_name == "Headphones":
- number = int(90)
- elif product_name == "Toaster":
- number = int(50)
- elif product_name == "Vinegar":
- number = int(10)
- elif product_name == "Rice":
- number = int(14)
- elif product_name == "Ice Cream":
- number = int(4)
- elif product_name == "Paper Towels":
- number = int(5)
- elif product_name == "Salt":
- number = int(4)
- except Exception as e:
- print (e)
- print (int(number))
- try:
- if product_name in cart_holder:
- cart_holder.remove(product_name)
- print ("Done the item {name_item_here} has been removed!".format(name_item_here = product_name))
- g = (', '.join(cart_holder))
- c = g
- # - Removing money - #
- if number in money_holder:
- money_holder.remove(number)
- q = [int(i) for i in money_holder]
- p = sum(q)
- money_cart = p
- try:
- cart.destroy()
- cart_loadup()
- except:
- pass
- elif product_name not in cart_holder:
- print ("Please enter a vaild product that is in your cart list!")
- print ("Once again your cart items are : \n{items_here}".format(items_here = c))
- except:
- pass
- def cart_menu():
- global cart_loadup
- def cart_loadup():
- global c,cart
- def Remove_Stuff():
- global c,Entry_to_remove_stuff
- remove_menu = Tk()
- remove_menu.title("Remove any items!")
- remove_menu.geometry("400x150") # w x h
- remove_menu.resizable(height = False, width = False)
- remove_menu.lift()
- print ("Your current items you can remove are :\n{items_listed}".format(items_listed = c))
- Info_label = Label(remove_menu, text = "Type anything you would like to remove!")
- Info_label.place(x = 0 , y = 0)
- Entry_to_remove_stuff = Entry(remove_menu)
- Entry_to_remove_stuff.place(x = 50, y = 50, width = 130)
- Info_Label_2 = Label(remove_menu, text = "The items are listed in console\nYou can type the name and press remove! \n(1 at a time)")
- Info_Label_2.place(x = 150, y = 50)
- Button_remove = Button(remove_menu, text = "Remove!", command = remove)
- Button_remove.place(x = 50, y = 100)
- cart = Tk()
- cart.title("Cart")
- cart.geometry("300x150") # w x h
- cart.resizable (height = False, width = True)
- cart.lift()
- try:
- Label_cart_items = Label(cart, text = "Your Cart Contains the following : \n{names_cart}\n".format(names_cart = c))
- Label_cart_items.place(x = 0 , y = 0)
- except:
- Nothing_contained = Label(cart, text = "You don't have anything in your cart!\nAdd items by visiting the menu.")
- Nothing_contained.place(x = 0 , y = 0)
- return
- Label_money_total = Label(cart, text = "Money total : {amount}".format(amount = money_cart))
- Label_money_total.place(x = 0, y = 40)
- remove_items = Button (cart, text = "Remove some items", command = Remove_Stuff)
- remove_items.place(x = 50, y = 70)
- Label_Cart = Label(root, text = "Cart : ")
- Label_Cart.config(font=("Courier",15))
- Label_Cart.place(x = 300, y = 0)
- Cart_button = Button(root, text = "View Cart!", command = cart_loadup)
- Cart_button.place(x = 250, y = 30,width = 150)
- def menu():
- def add_up_cart():
- global cart_holder,c,money_holder,money_cart, cart,cart_loadup
- cart_holder.insert(0, name) # inserts the items
- customized_cart = (', '.join(cart_holder))
- c = customized_cart
- # -- money -- #
- money_holder.insert(0, int(price))
- remake = [int(i) for i in money_holder]
- money_cart = sum(remake)
- check = len(c) != len(set(c)) # For duplicated items if u wanna turn it on tell me
- print ("Your cart now contains the following items : {names_stuff}".format(names_stuff = c))
- try:
- cart.destroy()
- cart_loadup() # For real time, so it updates :)
- except:
- pass
- def confirm():
- global price,name
- confirm = Tk()
- confirm.title("Confirm Option")
- confirm.geometry("300x150") # w x h
- confirm.resizable(height = False, width = False)
- confirm.lift()
- Label_Name = Label(confirm, text = "You chose {name_of_product}!".format(name_of_product = name))
- Label_Price = Label(confirm, text = "Price is : {price_of_product}{money_sign}!".format(price_of_product = price, money_sign = a))
- Label_Name.place(x = 0 , y = 0)
- Label_Price.place(x = 0, y = 40)
- Label_Name.config(font=("Courier",15))
- Label_Price.config(font=("Courier",15))
- Confirm_ADD_TO_CART = Button (confirm, text = "Add to cart!", command = add_up_cart)
- Confirm_ADD_TO_CART.place(x = 40, y = 80, width = 150)
- def pie_cmd():
- global price
- global name
- name = "Pie"
- price = int(4)
- confirm()
- def cake_cmd():
- global price,name
- name = "Cake"
- price = int(7)
- confirm()
- def chainsaw_cmd():
- global price,name
- name = "Chainsaw"
- price = int(20)
- confirm()
- def hammer_cmd():
- global price,name
- name = "Hammer"
- price = int(210)
- confirm()
- def beer_cmd():
- global price,name
- name = "Beer"
- price = int(1)
- confirm()
- def paper_cmd():
- global price,name
- name = "Paper"
- price = int(2)
- confirm()
- def cookies_cmd():
- global price,name
- name = "Cookies"
- price = int(2)
- confirm()
- def scissors_cmd():
- global price,name
- name = "Scissors"
- price = int(4)
- confirm()
- def socks_cmd():
- global price,name
- name = "Socks"
- price = int(2)
- confirm()
- def tape_cmd():
- global price,name
- name = "Tape"
- price = int(5)
- confirm()
- def lamp_cmd():
- global price,name
- name = "Lamp"
- price = int(25)
- confirm()
- def headphones_cmd():
- global price,name
- name = "Headphones"
- price = int(90)
- confirm()
- def toaster_cmd():
- global price,name
- name = "Toaster"
- price = int(50)
- confirm()
- def vinegar_cmd():
- global price,name
- name = "Vinegar"
- price = int(10)
- confirm()
- def rice_cmd():
- global price,name
- name = "Rice"
- price = int(14)
- confirm()
- def ice_cream_cmd():
- global price,name
- name = "Ice Cream"
- price = int(5)
- confirm()
- def salt_cmd():
- global price,name
- name = "Salt"
- price = int(4)
- confirm()
- def paper_towels_cmd():
- global price,name
- name = "Paper Towels"
- price = int(5)
- confirm()
- menu = Tk()
- menu.geometry("350x200") # w x h
- menu.title("Menu")
- menu.resizable(height = False, width = False)
- menu.lift()
- # - Cart Options - #
- pie_button = Button (menu, text = "Pie", command = pie_cmd)
- pie_button.place(x=0,y=0, width = 100)
- cake_button = Button(menu, text = "Cake", command = cake_cmd)
- cake_button.place(x = 0 , y = 30, width = 100)
- chainsaw_button = Button(menu, text = "Chainsaw", command = chainsaw_cmd)
- chainsaw_button.place(x = 0, y = 60, width = 100)
- hammer_button = Button(menu, text = "Hammer",command = hammer_cmd)
- hammer_button.place(x = 0 , y = 90, width = 100)
- beer_button = Button(menu, text = "Beer", command = beer_cmd)
- beer_button.place(x = 0 , y = 120, width = 100)
- paper_button = Button(menu, text = "Paper", command = paper_cmd)
- paper_button.place(x = 0 , y = 150, width = 100)
- cookies_button = Button(menu, text = "Cookies", command = cookies_cmd)
- cookies_button.place(x = 120 , y = 0, width = 100)
- scissors_button = Button(menu, text = "Scissors", command = scissors_cmd)
- scissors_button.place(x = 120, y = 30, width = 100)
- socks_button = Button (menu, text = "Socks", command = socks_cmd)
- socks_button.place(x = 120, y = 60, width = 100)
- tape_button = Button (menu, text = "Tape", command = tape_cmd)
- tape_button.place(x = 120, y = 90, width = 100)
- lamp_button = Button(menu, text = "Lamp", command = lamp_cmd)
- lamp_button.place(x = 120, y = 120, width= 100)
- headphones_button = Button(menu, text = "Headphones", command = headphones_cmd)
- headphones_button.place(x = 120, y = 150, width = 100)
- toaster_button = Button(menu, text = "Toaster", command = toaster_cmd)
- toaster_button.place(x = 240, y = 0, width = 100)
- vinegar_button = Button(menu, text = "Vinegar", command = vinegar_cmd)
- vinegar_button.place(x = 240, y = 30, width = 100)
- rice_button = Button(menu, text = "Rice", command = rice_cmd)
- rice_button.place(x = 240, y = 60, width = 100)
- icecream_button = Button(menu, text = "Ice Cream", command = ice_cream_cmd)
- icecream_button.place(x = 240, y = 90, width = 100)
- salt_button = Button(menu, text = "Salt", command = salt_cmd)
- salt_button.place(x = 240, y = 120, width = 100)
- paper_towels = Button(menu, text = "Paper Towels", command = paper_towels_cmd)
- paper_towels.place(x = 240, y = 150, width = 100)
- # -- Framework -- #
- root = Tk()
- root.geometry("450x200") # W x H
- root.title("Shopping idk")
- root.resizable(height = False, width = False)
- root.lift()
- Label_list = Label(root, text = "List : ")
- Label_list.config(font=("Courier",15))
- Label_list.place(x = 0 , y = 0)
- #Entry_List = Entry(root)
- #Entry_List.place(x = 0 , y = 30, width = 200)
- Label_pay = Label(root, text = "Pay : ")
- Label_pay.config(font=("Courier",15))
- Label_pay.place(x = 200 , y = 100)
- Entry_pay = Entry(root)
- Entry_pay.place(x = 170, y = 140, width = 150)
- # -- Menu Window -- #
- Button_List = Button(root, text = "Menu", command = menu)
- Button_List.place( x = 0, y = 30, width = 100)
- cart_menu()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement