Advertisement
xample

project half done

Dec 2nd, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.56 KB | None | 0 0
  1. from tkinter import *
  2.  
  3.  
  4.  
  5. # -- Def / commands -- #
  6. a = "€" # money sign
  7. cart_holder = [] # to hold items
  8. money_holder = [] # to hold money
  9. # - Menu - #
  10. def remove():
  11.     global Entry_to_remove_stuff,c,g,p,q,money_cart,number
  12.     print ("Function started")
  13.     product_name = (Entry_to_remove_stuff.get()).title()
  14.     print ("Product to remove {name_remove}".format(name_remove = product_name))
  15.     try:
  16.            
  17.         if product_name == "Pie":
  18.             number = int(4)
  19.         elif product_name == "Cake":
  20.             number = int(7)
  21.         elif product_name == "Chainsaw":
  22.             number = int(20)
  23.         elif product_name == "Hammer":
  24.             number = int(210)
  25.         elif product_name == "Beer":
  26.             number = int(1)
  27.         elif product_name == "Paper":
  28.             number = int(2)
  29.         elif product_name == "Cookies":
  30.             number = int(2)
  31.         elif product_name == "Scissors":
  32.             number = int(4)
  33.         elif product_name == "Socks":
  34.             number = int(2)
  35.         elif product_name == "Tape":
  36.             number = int (5)
  37.         elif product_name == "Lamp":
  38.             number = int(25)
  39.         elif product_name == "Headphones":
  40.             number = int(90)
  41.         elif product_name == "Toaster":
  42.             number = int(50)
  43.         elif product_name == "Vinegar":
  44.             number  = int(10)
  45.         elif product_name == "Rice":
  46.             number = int(14)
  47.         elif product_name == "Ice Cream":
  48.             number = int(4)
  49.         elif product_name == "Paper Towels":
  50.             number = int(5)
  51.         elif product_name == "Salt":
  52.             number = int(4)
  53.        
  54.     except Exception as e:
  55.         print (e)
  56.     print (int(number))
  57.        
  58.     try:
  59.         if product_name in cart_holder:
  60.             cart_holder.remove(product_name)
  61.             print ("Done the item {name_item_here} has been removed!".format(name_item_here = product_name))
  62.             g = (', '.join(cart_holder))
  63.             c = g
  64.             # - Removing money - #
  65.        
  66.         if number in money_holder:
  67.             money_holder.remove(number)
  68.             q = [int(i) for i in money_holder]
  69.             p = sum(q)
  70.             money_cart = p
  71.             try:
  72.                 cart.destroy()
  73.                 cart_loadup()
  74.             except:
  75.                 pass
  76.            
  77.         elif product_name not in cart_holder:
  78.             print ("Please enter a vaild product that is in your cart list!")
  79.             print ("Once again your cart items are : \n{items_here}".format(items_here = c))
  80.     except:
  81.         pass
  82.    
  83. def cart_menu():
  84.     global cart_loadup
  85.     def cart_loadup():
  86.         global c,cart
  87.         def Remove_Stuff():
  88.             global c,Entry_to_remove_stuff
  89.             remove_menu = Tk()
  90.             remove_menu.title("Remove any items!")
  91.             remove_menu.geometry("400x150")  # w x h
  92.             remove_menu.resizable(height = False, width = False)
  93.             remove_menu.lift()
  94.             print ("Your current items you can remove are :\n{items_listed}".format(items_listed = c))
  95.             Info_label = Label(remove_menu, text = "Type anything you would like to remove!")
  96.             Info_label.place(x = 0 , y = 0)
  97.             Entry_to_remove_stuff = Entry(remove_menu)
  98.             Entry_to_remove_stuff.place(x = 50, y = 50, width = 130)
  99.             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)")
  100.             Info_Label_2.place(x = 150, y = 50)
  101.             Button_remove =  Button(remove_menu, text = "Remove!", command = remove)
  102.             Button_remove.place(x = 50, y = 100)
  103.            
  104.         cart = Tk()
  105.         cart.title("Cart")
  106.         cart.geometry("300x150") # w x h
  107.         cart.resizable (height = False, width = True)
  108.         cart.lift()
  109.         try:
  110.             Label_cart_items = Label(cart, text = "Your Cart Contains the following : \n{names_cart}\n".format(names_cart = c))
  111.             Label_cart_items.place(x = 0 , y = 0)
  112.         except:
  113.             Nothing_contained = Label(cart, text = "You don't have anything in your cart!\nAdd items by visiting the menu.")
  114.             Nothing_contained.place(x = 0 , y = 0)
  115.             return
  116.         Label_money_total = Label(cart, text = "Money total : {amount}".format(amount = money_cart))
  117.         Label_money_total.place(x = 0, y = 40)
  118.         remove_items = Button (cart, text = "Remove some items", command = Remove_Stuff)
  119.         remove_items.place(x = 50, y = 70)
  120.        
  121.        
  122.        
  123.     Label_Cart = Label(root, text = "Cart : ")
  124.     Label_Cart.config(font=("Courier",15))
  125.     Label_Cart.place(x = 300, y = 0)
  126.  
  127.     Cart_button = Button(root, text = "View Cart!", command = cart_loadup)
  128.     Cart_button.place(x = 250, y = 30,width = 150)
  129. def menu():
  130.     def add_up_cart():
  131.         global cart_holder,c,money_holder,money_cart, cart,cart_loadup
  132.         cart_holder.insert(0, name) # inserts the items
  133.         customized_cart =  (', '.join(cart_holder))
  134.         c = customized_cart
  135.         # -- money -- #
  136.         money_holder.insert(0, int(price))
  137.         remake = [int(i) for i in money_holder]
  138.         money_cart = sum(remake)
  139.         check = len(c) != len(set(c)) # For duplicated items if u wanna turn it on tell me
  140.         print ("Your cart now contains the following items : {names_stuff}".format(names_stuff = c))
  141.         try:
  142.             cart.destroy()
  143.             cart_loadup() # For real time, so it updates :)
  144.         except:
  145.             pass
  146.        
  147.     def confirm():
  148.         global price,name
  149.         confirm = Tk()
  150.         confirm.title("Confirm Option")
  151.         confirm.geometry("300x150") # w x h
  152.         confirm.resizable(height = False, width = False)
  153.         confirm.lift()
  154.         Label_Name = Label(confirm, text = "You chose {name_of_product}!".format(name_of_product = name))
  155.         Label_Price = Label(confirm, text = "Price is : {price_of_product}{money_sign}!".format(price_of_product = price, money_sign = a))
  156.         Label_Name.place(x = 0 , y = 0)
  157.         Label_Price.place(x = 0, y = 40)
  158.         Label_Name.config(font=("Courier",15))
  159.         Label_Price.config(font=("Courier",15))
  160.         Confirm_ADD_TO_CART = Button (confirm, text = "Add to cart!", command = add_up_cart)
  161.         Confirm_ADD_TO_CART.place(x = 40, y = 80, width = 150)
  162.     def pie_cmd():
  163.         global price
  164.         global name
  165.         name = "Pie"
  166.         price = int(4)
  167.         confirm()
  168.     def cake_cmd():
  169.         global price,name
  170.         name = "Cake"
  171.         price = int(7)
  172.         confirm()
  173.     def chainsaw_cmd():
  174.         global price,name
  175.         name = "Chainsaw"
  176.         price = int(20)
  177.         confirm()
  178.     def hammer_cmd():
  179.         global price,name
  180.         name = "Hammer"
  181.         price = int(210)
  182.         confirm()
  183.     def beer_cmd():
  184.         global price,name
  185.         name = "Beer"
  186.         price = int(1)
  187.         confirm()
  188.     def paper_cmd():
  189.         global price,name
  190.         name = "Paper"
  191.         price = int(2)
  192.         confirm()
  193.     def cookies_cmd():
  194.         global price,name
  195.         name = "Cookies"
  196.         price = int(2)
  197.         confirm()
  198.     def scissors_cmd():
  199.         global price,name
  200.         name = "Scissors"
  201.         price = int(4)
  202.         confirm()
  203.     def socks_cmd():
  204.         global price,name
  205.         name = "Socks"
  206.         price = int(2)
  207.         confirm()
  208.     def tape_cmd():
  209.         global price,name
  210.         name = "Tape"
  211.         price = int(5)
  212.         confirm()
  213.     def lamp_cmd():
  214.         global price,name
  215.         name = "Lamp"
  216.         price = int(25)
  217.         confirm()
  218.     def headphones_cmd():
  219.         global price,name
  220.         name = "Headphones"
  221.         price = int(90)
  222.         confirm()
  223.     def toaster_cmd():
  224.         global price,name
  225.         name = "Toaster"
  226.         price = int(50)
  227.         confirm()
  228.     def vinegar_cmd():
  229.         global price,name
  230.         name = "Vinegar"
  231.         price = int(10)
  232.         confirm()
  233.     def rice_cmd():
  234.         global price,name
  235.         name = "Rice"
  236.         price = int(14)
  237.         confirm()
  238.     def ice_cream_cmd():
  239.         global price,name
  240.         name = "Ice Cream"
  241.         price = int(5)
  242.         confirm()
  243.     def salt_cmd():
  244.         global price,name
  245.         name = "Salt"
  246.         price = int(4)
  247.         confirm()
  248.     def paper_towels_cmd():
  249.         global price,name
  250.         name = "Paper Towels"
  251.         price = int(5)
  252.         confirm()
  253.  
  254.     menu = Tk()
  255.     menu.geometry("350x200") # w x h
  256.     menu.title("Menu")
  257.     menu.resizable(height = False, width = False)
  258.     menu.lift()
  259.     # - Cart Options - #
  260.     pie_button = Button (menu, text = "Pie", command = pie_cmd)
  261.     pie_button.place(x=0,y=0, width = 100)
  262.     cake_button = Button(menu, text = "Cake", command = cake_cmd)
  263.     cake_button.place(x = 0 , y = 30, width = 100)
  264.     chainsaw_button = Button(menu, text = "Chainsaw", command = chainsaw_cmd)
  265.     chainsaw_button.place(x = 0, y = 60, width = 100)
  266.     hammer_button = Button(menu, text = "Hammer",command = hammer_cmd)
  267.     hammer_button.place(x = 0 , y = 90, width = 100)
  268.     beer_button = Button(menu, text = "Beer", command = beer_cmd)
  269.     beer_button.place(x = 0 , y = 120, width = 100)
  270.     paper_button = Button(menu, text = "Paper", command = paper_cmd)
  271.     paper_button.place(x = 0 , y = 150, width = 100)
  272.     cookies_button = Button(menu, text = "Cookies", command = cookies_cmd)
  273.     cookies_button.place(x = 120 , y = 0, width = 100)
  274.     scissors_button = Button(menu, text = "Scissors", command = scissors_cmd)
  275.     scissors_button.place(x = 120, y = 30, width = 100)
  276.     socks_button = Button (menu, text = "Socks", command = socks_cmd)
  277.     socks_button.place(x = 120, y = 60, width = 100)
  278.     tape_button = Button (menu, text = "Tape", command = tape_cmd)
  279.     tape_button.place(x = 120, y = 90, width = 100)
  280.     lamp_button = Button(menu, text = "Lamp", command = lamp_cmd)
  281.     lamp_button.place(x = 120, y = 120, width= 100)
  282.     headphones_button = Button(menu, text = "Headphones", command = headphones_cmd)
  283.     headphones_button.place(x = 120, y = 150, width = 100)
  284.     toaster_button = Button(menu, text = "Toaster", command = toaster_cmd)
  285.     toaster_button.place(x = 240, y = 0, width = 100)
  286.     vinegar_button = Button(menu, text = "Vinegar", command = vinegar_cmd)
  287.     vinegar_button.place(x = 240, y = 30, width = 100)
  288.     rice_button = Button(menu, text = "Rice", command = rice_cmd)
  289.     rice_button.place(x = 240, y = 60, width = 100)
  290.     icecream_button = Button(menu, text = "Ice Cream", command = ice_cream_cmd)
  291.     icecream_button.place(x = 240, y = 90, width = 100)
  292.     salt_button = Button(menu, text = "Salt", command = salt_cmd)
  293.     salt_button.place(x = 240, y = 120, width = 100)
  294.     paper_towels = Button(menu, text = "Paper Towels", command = paper_towels_cmd)
  295.     paper_towels.place(x = 240, y = 150, width = 100)
  296.  
  297.  
  298. # -- Framework -- #
  299.  
  300. root = Tk()
  301. root.geometry("450x200") # W x H
  302. root.title("Shopping idk")
  303. root.resizable(height = False, width = False)
  304. root.lift()
  305.  
  306.  
  307. Label_list = Label(root, text = "List : ")
  308. Label_list.config(font=("Courier",15))
  309. Label_list.place(x = 0 , y = 0)
  310.  
  311. #Entry_List = Entry(root)
  312. #Entry_List.place(x = 0 , y = 30, width = 200)
  313.  
  314.  
  315.  
  316. Label_pay = Label(root, text = "Pay : ")
  317. Label_pay.config(font=("Courier",15))
  318. Label_pay.place(x = 200 , y = 100)
  319.  
  320. Entry_pay = Entry(root)
  321. Entry_pay.place(x = 170, y = 140, width = 150)
  322.  
  323.  
  324. # -- Menu Window -- #
  325.  
  326. Button_List = Button(root, text = "Menu", command = menu)
  327. Button_List.place( x = 0, y = 30, width = 100)
  328.  
  329. cart_menu()
  330.  
  331. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement