Advertisement
xample

project complete!!!

Dec 6th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 19.34 KB | None | 0 0
  1. from tkinter import *
  2. from tkinter import messagebox
  3. import os
  4. print ("Loading...")
  5. # -- Def / commands -- #
  6. a = "€" # money sign
  7. cart_holder = [] # to hold items
  8. money_holder = [] # to hold money
  9. closed = True # Do not remove
  10. money_value = False # do not remove, its for payment and cart real time update
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18. # -- messy code starts here lol -- #
  19.  
  20.  
  21.  
  22. def cord():
  23.     global x_sp,y_sp
  24.     if closed == False:
  25.         x_sp = (main.winfo_x())
  26.         y_sp = (main.winfo_y())
  27.         return
  28.     else:
  29.         x_sp = "0"
  30.         y_sp = "0"
  31.         return
  32.    
  33.  
  34. def Payment_menu():
  35.     global c,Remove_money_value,money_cart,menu_open
  36.     z = len(cart_holder)
  37.     if z == 0:
  38.         messagebox.showinfo("Add stuff", "Add stuff to your cart to pay!")
  39.         menu_open = True
  40.         menu()
  41.         return
  42.     def Remove_money_value():
  43.         global total_amount_m,money_holder,subt,money_cart,c, cart_holder,money_value
  44.        
  45.        
  46.            
  47.         total_amount_m = (money_cart)
  48.         if total_amount_m == 0:
  49.             messagebox.showinfo("You're done!", "You don't have to pay anymore!")
  50.             return
  51.         if value > total_amount_m:
  52.             messagebox.showinfo("Paying too much!", "Pay less! You're paying {money}{amount_paying} and you only have to pay {g_money}{need_to_pay}".format(
  53.                 money = a,
  54.                 amount_paying = value,
  55.                 g_money =a,
  56.                 need_to_pay = total_amount_m))
  57.            
  58.         else:
  59.             money_value = True
  60.             subt = float(total_amount_m - value)
  61.             money_cart = float(subt)
  62.             if closed == False:  
  63.                
  64.                 cord()
  65.                 main.destroy()
  66.                 cart_loadup(x_sp,y_sp) # real time
  67.             else:
  68.                 pass
  69.            
  70.            
  71.        
  72.        
  73.     # -- GUI -- #
  74.     payment = Tk()
  75.     payment.title("Payment")
  76.     payment.geometry("300x150") # w x h
  77.     payment.resizable(height = False, width = False)
  78.     payment.lift()
  79.  
  80.     # -- settings for payment -- #
  81.     Label_pay = Label(payment, text = "Amount you're paying : ")
  82.     Label_pay.config(font=("Courier",12))
  83.     Label_pay.place (x = 0 , y = 0 )
  84.  
  85.  
  86.  
  87.     # -- First Row -- #
  88.     def bu_01():
  89.         global value
  90.         value = float(0.1)
  91.         Remove_money_value()
  92.     def bu_02():
  93.         global value
  94.         value = float(0.2)
  95.         Remove_money_value()
  96.     def bu_03():
  97.         global value
  98.         value = float(0.3)
  99.         Remove_money_value()
  100.     def bu_05():
  101.         global value
  102.         value = float(0.5)
  103.         Remove_money_value()
  104.     def bu_10():
  105.         global value
  106.         value = float(0.10)
  107.         Remove_money_value()
  108.     def bu_20():
  109.         global value
  110.         value = float(0.20)
  111.         Remove_money_value()
  112.     def bu_50():
  113.         global value
  114.         value = float(0.50)
  115.         Remove_money_value()
  116.     def bu_1_whole():
  117.         global value
  118.         value = float(1)
  119.         Remove_money_value()
  120.     def bu_2_whole():
  121.         global value
  122.         value = float(2)
  123.         Remove_money_value()
  124.     def bu_5_whole():
  125.         global value
  126.         value = float(5)
  127.         Remove_money_value()
  128.     def bu_10_whole():
  129.         global value
  130.         value = float(10)
  131.         Remove_money_value()
  132.     def bu_20_whole():
  133.         global value
  134.         value = float(20)
  135.         Remove_money_value()
  136.     def bu_50_whole():
  137.         global value
  138.         value = float(50)
  139.         Remove_money_value()
  140.     def bu_100_whole():
  141.         global value
  142.         value = float(100)
  143.         Remove_money_value()
  144.     button_01 = Button(payment, text = "{a}0,01".format(a=a), command = bu_01)
  145.     button_01.place(x = 15, y = 40)
  146.     button_02 = Button(payment, text = "{a}0,02".format(a=a), command = bu_02)
  147.     button_02.place(x = 60, y = 40)
  148.     button_05 = Button(payment, text = "{a}0,05".format(a=a), command = bu_05)
  149.     button_05.place(x = 105, y = 40)
  150.     button_010 = Button(payment, text = "{a}0,10".format(a=a), command = bu_10)
  151.     button_010.place(x = 150, y = 40)
  152.     button_020 = Button(payment, text = "{a}0,20".format(a=a), command = bu_20)
  153.     button_020.place(x = 195 , y = 40)
  154.     button_050 = Button(payment, text = "{a}0,50".format(a=a), command = bu_50)
  155.     button_050.place(x = 240, y = 40)
  156.  
  157.     # -- Second Row -- #
  158.     button_1 = Button(payment, text = "{a}1".format(a=a), command = bu_1_whole)
  159.     button_1.place(x = 10 , y = 80)
  160.     button_2 = Button(payment, text = "{a}2".format(a=a), command = bu_2_whole)
  161.     button_2.place(x = 40, y = 80)
  162.     button_5 = Button(payment, text = "{a}5".format(a=a), command = bu_5_whole)
  163.     button_5.place(x = 70, y = 80)
  164.     button_10 = Button(payment, text = "{a}10".format(a=a), command = bu_10_whole)
  165.     button_10.place(x = 105, y = 80)
  166.     button_20 = Button(payment, text = "{a}20".format(a=a), command = bu_20_whole)
  167.     button_20.place(x = 150, y = 80)
  168.     button_50 = Button(payment, text = "{a}50".format(a=a), command = bu_50_whole)
  169.     button_50.place(x = 195, y = 80)
  170.     button_100 = Button(payment, text = "{a}100".format(a=a), command = bu_100_whole)
  171.     button_100.place(x = 240, y = 80)
  172.  
  173. # removing items def's
  174.  
  175. def removing_items_selection():
  176.     global mylist, cart_holder,money_holder
  177.     selection = mylist.curselection()
  178.     value = mylist.get(selection[0])
  179.     r = ''.join([i for i in value if not i.isdigit()])
  180.     m = r.replace(a, "").replace(" ", "") # cart items
  181.     b = ''.join(i for i in value if i.isdigit())
  182.     i = b.replace(" ", "").replace(a, "") # money cart
  183.     # -- double space function check -- #
  184.     if "Ice" in m:
  185.         z = m.replace("IceCream", "Ice Cream")
  186.         #resign
  187.         m = z
  188.     else:
  189.         pass
  190.     if "Paper" in m:
  191.         g = m.replace("PaperTowels", "Paper Towels")
  192.         #resign
  193.         m = g
  194.     else:
  195.         pass
  196.    
  197.    
  198.        
  199.     try:
  200.         mylist.delete(mylist.curselection())
  201.         if m in cart_holder:
  202.             try:
  203.                 print ("Removing {item}.".format(item = m))
  204.                 cart_holder.remove(m)
  205.                 # -- now price -- #
  206.                 money_holder.remove(int(i))
  207.                 # -- update real time -- #
  208.                 cord()
  209.                 main.destroy()
  210.                 cart_loadup(x_sp,y_sp)
  211.             except Exception as error_remove:
  212.                 print (error_remove)
  213.            
  214.     except:
  215.         messagebox.showinfo("Error", "Please select one item at a time to remove!")
  216.         return
  217.    
  218.    
  219.  
  220.    
  221.    
  222. def cart_menu():
  223.     global cart_loadup,main
  224.     def cart_loadup(supply_x,supply_y):
  225.         global c,cart,item,cart_holder,money_holder,money_value
  226.         # -- Checking(s) -- #
  227.         num_counter = len(cart_holder)
  228.         if num_counter == 0:
  229.             messagebox.showinfo("Error!", "Add stuff to your cart so you can view them here!")
  230.             menu()
  231.             return
  232.        
  233.        
  234.            
  235.            
  236.        
  237.        
  238.         global closed,main
  239.         closed = False
  240.         main = Tk()
  241.         try:
  242.             main.geometry("550x350+%d+%d"%(supply_x,supply_y)) # w x h
  243.         except:
  244.             main.geometry("500x350+0+0")
  245.         main.resizable(height = False, width = False)
  246.         main.title("Cart")
  247.         main.lift()
  248.  
  249.         # -- money update -- #
  250.        
  251.         # from cart function
  252.         remake = [int(i) for i in money_holder]
  253.         money_cart = sum(remake)
  254.  
  255.        
  256.         # -- do not remove this -- #
  257.        
  258.         def on_closing():
  259.             global closed
  260.             closed = True
  261.             main.destroy()
  262.  
  263.        
  264.         main.protocol("WM_DELETE_WINDOW", on_closing)
  265.  
  266.        
  267.         label_item = Label(main, text = "items")
  268.         label_item.config(font=("Times",25, "bold"))
  269.         label_item.place(x = 150, y = 0)
  270.  
  271.         to_remove = Label(main, text = "Click the item you want\n to remove.")
  272.         to_remove.place(x = 0 , y = 0)
  273.  
  274.         label_price = Label(main, text = "price")
  275.         label_price.config(font=("Times",25, "bold"))
  276.         label_price.place(x = 300, y = 0 )
  277.  
  278.         middle_line = Label(main, text = "|\n|\n|\n|")
  279.         middle_line.place(x = 260, y = 0)
  280.  
  281.         global mylist
  282.         mylist = Listbox(main,selectmode=MULTIPLE,bd=1,height=10,width = 45)
  283.         mylist.place(x = 130, y = 50)
  284.  
  285.         scroll = Scrollbar(main, orient = "vertical")
  286.         scroll.config(command=mylist.yview)
  287.         scroll.pack(side = "right", fill = Y)
  288.  
  289.         mylist.config(yscrollcommand=scroll.set)
  290.         scroll.config(command=mylist.yview)
  291.         # - ultimate code skillz lel - #
  292.         beer_space = "                                                       "
  293.         pie_space = "                                                         "
  294.         cake_space = "                                                      "
  295.         chainsaw_space ="                                             "
  296.         hammer_space ="                                              "
  297.         paper_space ="                                                     "
  298.         cookies_space = "                                                 "
  299.         scissors_space = "                                                 "
  300.         socks_space= "                                                     "
  301.         tape_space = "                                                      "
  302.         lamp_space = "                                                    "
  303.         headphone_space = "                                       "
  304.         toaster_space = "                                                 "
  305.         vinegar_space = "                                                "
  306.         rice_space = "                                                      "
  307.         ice_cream_space = "                                            "
  308.         salt_space = "                                                       "
  309.         paper_towels_space = "                                      "
  310.         remove_button = Button(main, text = "Remove selected\n items!", command = removing_items_selection)
  311.         remove_button.place(x = 0, y = 35, width = 100)
  312.         def item(name,type_space,price):
  313.            mylist.insert(0,name + type_space + a +str(price))
  314.         if "Pie" in cart_holder:
  315.             item("Pie",pie_space,4)
  316.         if "Cake" in cart_holder:
  317.             item("Cake",cake_space,7)
  318.         if "Beer" in cart_holder:
  319.             item("Beer",beer_space,7)
  320.         if "Chainsaw" in cart_holder:
  321.             item("Chainsaw",chainsaw_space,20)
  322.         if "Hammer" in cart_holder:
  323.             item("Hammer", hammer_space,210)
  324.         if "Paper" in cart_holder:
  325.           item("Paper", paper_space,2)
  326.         if "Cookies" in cart_holder:
  327.             item("Cookies", cookies_space, 2)
  328.         if "Scissors" in cart_holder:
  329.             item("Scissors", scissors_space,4)
  330.         if "Socks" in cart_holder:
  331.             item("Socks", socks_space,2)
  332.         if "Tape" in cart_holder:
  333.             item("Tape", tape_space,5)
  334.         if "Lamp" in cart_holder:
  335.             item("Lamp", lamp_space,25)
  336.         if "Headphones" in cart_holder:
  337.             item("Headphones", headphone_space,90)
  338.         if "Toaster" in cart_holder:
  339.             item("Toaster", toaster_space,50)
  340.         if "Vinegar" in cart_holder:
  341.             item("Vinegar", vinegar_space, 10)
  342.         if "Rice" in cart_holder:
  343.             item("Rice", rice_space, 14)
  344.         if "Ice Cream" in cart_holder:
  345.             item("Ice Cream", ice_cream_space,5)
  346.         if "Salt" in cart_holder:
  347.             item("Salt", salt_space,5)
  348.         if "Paper Towels" in cart_holder:
  349.             item("Paper Towels", paper_towels_space, 5)
  350.        
  351.         if money_value == False:
  352.             Label_money_total = Label(main, text = "Money total : {money_euro_sign}{amount}".format(money_euro_sign = a , amount = money_cart))
  353.             Label_money_total.config(font=("Courier",15))
  354.             Label_money_total.place(x = 150, y = 220)
  355.         if money_value == True:
  356.             Label_money_total = Label(main, text = "Money total left to pay : {money_euro_sign}{amount}".format(money_euro_sign = a , amount = subt))
  357.             Label_money_total.config(font=("Courier",15))
  358.             Label_money_total.place(x = 100, y = 220)
  359.        
  360.  
  361.  
  362.        
  363.     Label_Cart = Label(root, text = "Cart : ")
  364.     Label_Cart.config(font=("Courier",15))
  365.     Label_Cart.place(x = 300, y = 0)
  366.     cord()
  367.     Cart_button = Button(root, text = "View Cart!", command = lambda: cart_loadup(x_sp,y_sp))
  368.     Cart_button.place(x = 250, y = 30,width = 150)
  369. def menu():
  370.     def add_up_cart():
  371.         global cart_holder,c,money_holder,money_cart, cart,cart_loadup,closed,x_sp,y_sp
  372.         cart_holder.insert(0, name) # inserts the items
  373.         customized_cart =  (', '.join(cart_holder))
  374.         c = customized_cart
  375.         # -- money -- #
  376.         money_holder.insert(0, int(price))
  377.         remake = [int(i) for i in money_holder]
  378.         money_cart = sum(remake)
  379.         check = len(c) != len(set(c)) # For duplicated items if u wanna turn it on tell me
  380.         print ("Item has been added. ({names_stuff})".format(names_stuff = name))
  381.         try:
  382.             if closed == False:
  383.                 cord()
  384.                 main.destroy()
  385.                 cart_loadup(x_sp,y_sp) # For real time, so it updates :)
  386.             elif closed == True:
  387.                 pass
  388.            
  389.         except Exception as woot : # breakpoint #
  390.             pass
  391.         # -- confirm function -- #
  392.     def confirm():
  393.         global price,name
  394.         add_up_cart()
  395.  
  396.         # -- items cmd's -- #
  397.     def pie_cmd():
  398.         global price
  399.         global name
  400.         name = "Pie"
  401.         price = int(4)
  402.         confirm()
  403.     def cake_cmd():
  404.         global price,name
  405.         name = "Cake"
  406.         price = int(7)
  407.         confirm()
  408.     def chainsaw_cmd():
  409.         global price,name
  410.         name = "Chainsaw"
  411.         price = int(20)
  412.         confirm()
  413.     def hammer_cmd():
  414.         global price,name
  415.         name = "Hammer"
  416.         price = int(210)
  417.         confirm()
  418.     def beer_cmd():
  419.         global price,name
  420.         name = "Beer"
  421.         price = int(1)
  422.         confirm()
  423.     def paper_cmd():
  424.         global price,name
  425.         name = "Paper"
  426.         price = int(2)
  427.         confirm()
  428.     def cookies_cmd():
  429.         global price,name
  430.         name = "Cookies"
  431.         price = int(2)
  432.         confirm()
  433.     def scissors_cmd():
  434.         global price,name
  435.         name = "Scissors"
  436.         price = int(4)
  437.         confirm()
  438.     def socks_cmd():
  439.         global price,name
  440.         name = "Socks"
  441.         price = int(2)
  442.         confirm()
  443.     def tape_cmd():
  444.         global price,name
  445.         name = "Tape"
  446.         price = int(5)
  447.         confirm()
  448.     def lamp_cmd():
  449.         global price,name
  450.         name = "Lamp"
  451.         price = int(25)
  452.         confirm()
  453.     def headphones_cmd():
  454.         global price,name
  455.         name = "Headphones"
  456.         price = int(90)
  457.         confirm()
  458.     def toaster_cmd():
  459.         global price,name
  460.         name = "Toaster"
  461.         price = int(50)
  462.         confirm()
  463.     def vinegar_cmd():
  464.         global price,name
  465.         name = "Vinegar"
  466.         price = int(10)
  467.         confirm()
  468.     def rice_cmd():
  469.         global price,name
  470.         name = "Rice"
  471.         price = int(14)
  472.         confirm()
  473.     def ice_cream_cmd():
  474.         global price,name
  475.         name = "Ice Cream"
  476.         price = int(5)
  477.         confirm()
  478.     def salt_cmd():
  479.         global price,name
  480.         name = "Salt"
  481.         price = int(4)
  482.         confirm()
  483.     def paper_towels_cmd():
  484.         global price,name
  485.         name = "Paper Towels"
  486.         price = int(5)
  487.         confirm()
  488.    
  489.     menu = Tk()
  490.     menu.geometry("350x200") # w x h
  491.     menu.title("Menu")
  492.     menu.resizable(height = False, width = False)
  493.     menu.lift()
  494.     # - Cart Options - #
  495.     pie_button = Button (menu, text = "{a}4 ~ Pie".format(a = a), command = pie_cmd)
  496.     pie_button.place(x=0,y=0, width = 100)
  497.     cake_button = Button(menu, text = "{a}7 ~ Cake".format(a = a), command = cake_cmd)
  498.     cake_button.place(x = 0 , y = 30, width = 100)
  499.     chainsaw_button = Button(menu, text = "{a}20 ~ Chainsaw".format(a = a), command = chainsaw_cmd)
  500.     chainsaw_button.place(x = 0, y = 60, width = 100)
  501.     hammer_button = Button(menu, text = "{a}210 ~ Hammer".format(a = a),command = hammer_cmd)
  502.     hammer_button.place(x = 0 , y = 90, width = 100)
  503.     beer_button = Button(menu, text = "{a}1 ~ Beer".format(a = a), command = beer_cmd)
  504.     beer_button.place(x = 0 , y = 120, width = 100)
  505.     paper_button = Button(menu, text = "{a}2 ~ Paper".format(a = a), command = paper_cmd)
  506.     paper_button.place(x = 0 , y = 150, width = 100)
  507.     cookies_button = Button(menu, text = "{a}2 ~ Cookies".format(a = a), command = cookies_cmd)
  508.     cookies_button.place(x = 120 , y = 0, width = 100)
  509.     scissors_button = Button(menu, text = "{a}4 ~ Scissors".format(a = a), command = scissors_cmd)
  510.     scissors_button.place(x = 120, y = 30, width = 100)
  511.     socks_button = Button (menu, text = "{a}2 ~ Socks".format(a = a), command = socks_cmd)
  512.     socks_button.place(x = 120, y = 60, width = 100)
  513.     tape_button = Button (menu, text = "{a}5 ~ Tape".format(a = a), command = tape_cmd)
  514.     tape_button.place(x = 120, y = 90, width = 100)
  515.     lamp_button = Button(menu, text = "{a}25 ~ Lamp".format(a = a), command = lamp_cmd)
  516.     lamp_button.place(x = 120, y = 120, width= 100)
  517.     headphones_button = Button(menu, text = "{a}90 ~ Headphones".format(a = a), command = headphones_cmd)
  518.     headphones_button.place(x = 120, y = 150, width = 100)
  519.     toaster_button = Button(menu, text = "{a}50 ~ Toaster".format(a = a), command = toaster_cmd)
  520.     toaster_button.place(x = 240, y = 0, width = 100)
  521.     vinegar_button = Button(menu, text = "{a}10 ~ Vinegar".format(a = a), command = vinegar_cmd)
  522.     vinegar_button.place(x = 240, y = 30, width = 100)
  523.     rice_button = Button(menu, text = "{a}14 ~ Rice".format(a = a), command = rice_cmd)
  524.     rice_button.place(x = 240, y = 60, width = 100)
  525.     icecream_button = Button(menu, text = "{a}5 ~ Ice Cream".format(a = a), command = ice_cream_cmd)
  526.     icecream_button.place(x = 240, y = 90, width = 100)
  527.     salt_button = Button(menu, text = "{a}4 ~ Salt".format(a = a), command = salt_cmd)
  528.     salt_button.place(x = 240, y = 120, width = 100)
  529.     paper_towels = Button(menu, text = "{a}5 ~ Paper Towels".format(a = a), command = paper_towels_cmd)
  530.     paper_towels.place(x = 240, y = 150, width = 100)
  531.     menu.mainloop()
  532.  
  533.  
  534. # -- Framework -- #
  535.  
  536. root = Tk()
  537. root.geometry("450x200+500+350") # W x H + X + Y
  538. root.attributes("-topmost", True)
  539. root.title("Shopping")
  540. root.resizable(height = False, width = False)
  541. root.lift()
  542.  
  543.  
  544. Label_list = Label(root, text = "List : ")
  545. Label_list.config(font=("Courier",15))
  546. Label_list.place(x = 0 , y = 0)
  547.  
  548. Label_pay = Label(root, text = "Pay : ")
  549. Label_pay.config(font=("Courier",15))
  550. Label_pay.place(x = 200 , y = 100)
  551.  
  552. #Entry_List = Entry(root)
  553. #Entry_List.place(x = 0 , y = 30, width = 200)
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560. # -- Menu Window -- #
  561.  
  562. Button_List = Button(root, text = "Menu", command = menu)
  563. Button_List.place( x = 0, y = 30, width = 100)
  564.  
  565. Button_pay = Button(root, text = "Pay", command = Payment_menu)
  566. Button_pay.place(x = 170, y = 140, width = 150)
  567.  
  568.  
  569. os.system("title Shopping Console")
  570.  
  571.  
  572. cart_menu()
  573.  
  574.  
  575.  
  576. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement