Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import messagebox
- import os
- print ("Loading...")
- # -- Def / commands -- #
- a = "€" # money sign
- cart_holder = [] # to hold items
- money_holder = [] # to hold money
- closed = True # Do not remove
- money_value = False # do not remove, its for payment and cart real time update
- # -- messy code starts here lol -- #
- def cord():
- global x_sp,y_sp
- if closed == False:
- x_sp = (main.winfo_x())
- y_sp = (main.winfo_y())
- return
- else:
- x_sp = "0"
- y_sp = "0"
- return
- def Payment_menu():
- global c,Remove_money_value,money_cart,menu_open
- z = len(cart_holder)
- if z == 0:
- messagebox.showinfo("Add stuff", "Add stuff to your cart to pay!")
- menu_open = True
- menu()
- return
- def Remove_money_value():
- global total_amount_m,money_holder,subt,money_cart,c, cart_holder,money_value
- total_amount_m = (money_cart)
- if total_amount_m == 0:
- messagebox.showinfo("You're done!", "You don't have to pay anymore!")
- return
- if value > total_amount_m:
- 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(
- money = a,
- amount_paying = value,
- g_money =a,
- need_to_pay = total_amount_m))
- else:
- money_value = True
- subt = float(total_amount_m - value)
- money_cart = float(subt)
- if closed == False:
- cord()
- main.destroy()
- cart_loadup(x_sp,y_sp) # real time
- else:
- pass
- # -- GUI -- #
- payment = Tk()
- payment.title("Payment")
- payment.geometry("300x150") # w x h
- payment.resizable(height = False, width = False)
- payment.lift()
- # -- settings for payment -- #
- Label_pay = Label(payment, text = "Amount you're paying : ")
- Label_pay.config(font=("Courier",12))
- Label_pay.place (x = 0 , y = 0 )
- # -- First Row -- #
- def bu_01():
- global value
- value = float(0.1)
- Remove_money_value()
- def bu_02():
- global value
- value = float(0.2)
- Remove_money_value()
- def bu_03():
- global value
- value = float(0.3)
- Remove_money_value()
- def bu_05():
- global value
- value = float(0.5)
- Remove_money_value()
- def bu_10():
- global value
- value = float(0.10)
- Remove_money_value()
- def bu_20():
- global value
- value = float(0.20)
- Remove_money_value()
- def bu_50():
- global value
- value = float(0.50)
- Remove_money_value()
- def bu_1_whole():
- global value
- value = float(1)
- Remove_money_value()
- def bu_2_whole():
- global value
- value = float(2)
- Remove_money_value()
- def bu_5_whole():
- global value
- value = float(5)
- Remove_money_value()
- def bu_10_whole():
- global value
- value = float(10)
- Remove_money_value()
- def bu_20_whole():
- global value
- value = float(20)
- Remove_money_value()
- def bu_50_whole():
- global value
- value = float(50)
- Remove_money_value()
- def bu_100_whole():
- global value
- value = float(100)
- Remove_money_value()
- button_01 = Button(payment, text = "{a}0,01".format(a=a), command = bu_01)
- button_01.place(x = 15, y = 40)
- button_02 = Button(payment, text = "{a}0,02".format(a=a), command = bu_02)
- button_02.place(x = 60, y = 40)
- button_05 = Button(payment, text = "{a}0,05".format(a=a), command = bu_05)
- button_05.place(x = 105, y = 40)
- button_010 = Button(payment, text = "{a}0,10".format(a=a), command = bu_10)
- button_010.place(x = 150, y = 40)
- button_020 = Button(payment, text = "{a}0,20".format(a=a), command = bu_20)
- button_020.place(x = 195 , y = 40)
- button_050 = Button(payment, text = "{a}0,50".format(a=a), command = bu_50)
- button_050.place(x = 240, y = 40)
- # -- Second Row -- #
- button_1 = Button(payment, text = "{a}1".format(a=a), command = bu_1_whole)
- button_1.place(x = 10 , y = 80)
- button_2 = Button(payment, text = "{a}2".format(a=a), command = bu_2_whole)
- button_2.place(x = 40, y = 80)
- button_5 = Button(payment, text = "{a}5".format(a=a), command = bu_5_whole)
- button_5.place(x = 70, y = 80)
- button_10 = Button(payment, text = "{a}10".format(a=a), command = bu_10_whole)
- button_10.place(x = 105, y = 80)
- button_20 = Button(payment, text = "{a}20".format(a=a), command = bu_20_whole)
- button_20.place(x = 150, y = 80)
- button_50 = Button(payment, text = "{a}50".format(a=a), command = bu_50_whole)
- button_50.place(x = 195, y = 80)
- button_100 = Button(payment, text = "{a}100".format(a=a), command = bu_100_whole)
- button_100.place(x = 240, y = 80)
- # removing items def's
- def removing_items_selection():
- global mylist, cart_holder,money_holder
- selection = mylist.curselection()
- value = mylist.get(selection[0])
- r = ''.join([i for i in value if not i.isdigit()])
- m = r.replace(a, "").replace(" ", "") # cart items
- b = ''.join(i for i in value if i.isdigit())
- i = b.replace(" ", "").replace(a, "") # money cart
- # -- double space function check -- #
- if "Ice" in m:
- z = m.replace("IceCream", "Ice Cream")
- #resign
- m = z
- else:
- pass
- if "Paper" in m:
- g = m.replace("PaperTowels", "Paper Towels")
- #resign
- m = g
- else:
- pass
- try:
- mylist.delete(mylist.curselection())
- if m in cart_holder:
- try:
- print ("Removing {item}.".format(item = m))
- cart_holder.remove(m)
- # -- now price -- #
- money_holder.remove(int(i))
- # -- update real time -- #
- cord()
- main.destroy()
- cart_loadup(x_sp,y_sp)
- except Exception as error_remove:
- print (error_remove)
- except:
- messagebox.showinfo("Error", "Please select one item at a time to remove!")
- return
- def cart_menu():
- global cart_loadup,main
- def cart_loadup(supply_x,supply_y):
- global c,cart,item,cart_holder,money_holder,money_value
- # -- Checking(s) -- #
- num_counter = len(cart_holder)
- if num_counter == 0:
- messagebox.showinfo("Error!", "Add stuff to your cart so you can view them here!")
- menu()
- return
- global closed,main
- closed = False
- main = Tk()
- try:
- main.geometry("550x350+%d+%d"%(supply_x,supply_y)) # w x h
- except:
- main.geometry("500x350+0+0")
- main.resizable(height = False, width = False)
- main.title("Cart")
- main.lift()
- # -- money update -- #
- # from cart function
- remake = [int(i) for i in money_holder]
- money_cart = sum(remake)
- # -- do not remove this -- #
- def on_closing():
- global closed
- closed = True
- main.destroy()
- main.protocol("WM_DELETE_WINDOW", on_closing)
- label_item = Label(main, text = "items")
- label_item.config(font=("Times",25, "bold"))
- label_item.place(x = 150, y = 0)
- to_remove = Label(main, text = "Click the item you want\n to remove.")
- to_remove.place(x = 0 , y = 0)
- label_price = Label(main, text = "price")
- label_price.config(font=("Times",25, "bold"))
- label_price.place(x = 300, y = 0 )
- middle_line = Label(main, text = "|\n|\n|\n|")
- middle_line.place(x = 260, y = 0)
- global mylist
- mylist = Listbox(main,selectmode=MULTIPLE,bd=1,height=10,width = 45)
- mylist.place(x = 130, y = 50)
- scroll = Scrollbar(main, orient = "vertical")
- scroll.config(command=mylist.yview)
- scroll.pack(side = "right", fill = Y)
- mylist.config(yscrollcommand=scroll.set)
- scroll.config(command=mylist.yview)
- # - ultimate code skillz lel - #
- beer_space = " "
- pie_space = " "
- cake_space = " "
- chainsaw_space =" "
- hammer_space =" "
- paper_space =" "
- cookies_space = " "
- scissors_space = " "
- socks_space= " "
- tape_space = " "
- lamp_space = " "
- headphone_space = " "
- toaster_space = " "
- vinegar_space = " "
- rice_space = " "
- ice_cream_space = " "
- salt_space = " "
- paper_towels_space = " "
- remove_button = Button(main, text = "Remove selected\n items!", command = removing_items_selection)
- remove_button.place(x = 0, y = 35, width = 100)
- def item(name,type_space,price):
- mylist.insert(0,name + type_space + a +str(price))
- if "Pie" in cart_holder:
- item("Pie",pie_space,4)
- if "Cake" in cart_holder:
- item("Cake",cake_space,7)
- if "Beer" in cart_holder:
- item("Beer",beer_space,7)
- if "Chainsaw" in cart_holder:
- item("Chainsaw",chainsaw_space,20)
- if "Hammer" in cart_holder:
- item("Hammer", hammer_space,210)
- if "Paper" in cart_holder:
- item("Paper", paper_space,2)
- if "Cookies" in cart_holder:
- item("Cookies", cookies_space, 2)
- if "Scissors" in cart_holder:
- item("Scissors", scissors_space,4)
- if "Socks" in cart_holder:
- item("Socks", socks_space,2)
- if "Tape" in cart_holder:
- item("Tape", tape_space,5)
- if "Lamp" in cart_holder:
- item("Lamp", lamp_space,25)
- if "Headphones" in cart_holder:
- item("Headphones", headphone_space,90)
- if "Toaster" in cart_holder:
- item("Toaster", toaster_space,50)
- if "Vinegar" in cart_holder:
- item("Vinegar", vinegar_space, 10)
- if "Rice" in cart_holder:
- item("Rice", rice_space, 14)
- if "Ice Cream" in cart_holder:
- item("Ice Cream", ice_cream_space,5)
- if "Salt" in cart_holder:
- item("Salt", salt_space,5)
- if "Paper Towels" in cart_holder:
- item("Paper Towels", paper_towels_space, 5)
- if money_value == False:
- Label_money_total = Label(main, text = "Money total : {money_euro_sign}{amount}".format(money_euro_sign = a , amount = money_cart))
- Label_money_total.config(font=("Courier",15))
- Label_money_total.place(x = 150, y = 220)
- if money_value == True:
- Label_money_total = Label(main, text = "Money total left to pay : {money_euro_sign}{amount}".format(money_euro_sign = a , amount = subt))
- Label_money_total.config(font=("Courier",15))
- Label_money_total.place(x = 100, y = 220)
- Label_Cart = Label(root, text = "Cart : ")
- Label_Cart.config(font=("Courier",15))
- Label_Cart.place(x = 300, y = 0)
- cord()
- Cart_button = Button(root, text = "View Cart!", command = lambda: cart_loadup(x_sp,y_sp))
- 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,closed,x_sp,y_sp
- 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 ("Item has been added. ({names_stuff})".format(names_stuff = name))
- try:
- if closed == False:
- cord()
- main.destroy()
- cart_loadup(x_sp,y_sp) # For real time, so it updates :)
- elif closed == True:
- pass
- except Exception as woot : # breakpoint #
- pass
- # -- confirm function -- #
- def confirm():
- global price,name
- add_up_cart()
- # -- items cmd's -- #
- 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 = "{a}4 ~ Pie".format(a = a), command = pie_cmd)
- pie_button.place(x=0,y=0, width = 100)
- cake_button = Button(menu, text = "{a}7 ~ Cake".format(a = a), command = cake_cmd)
- cake_button.place(x = 0 , y = 30, width = 100)
- chainsaw_button = Button(menu, text = "{a}20 ~ Chainsaw".format(a = a), command = chainsaw_cmd)
- chainsaw_button.place(x = 0, y = 60, width = 100)
- hammer_button = Button(menu, text = "{a}210 ~ Hammer".format(a = a),command = hammer_cmd)
- hammer_button.place(x = 0 , y = 90, width = 100)
- beer_button = Button(menu, text = "{a}1 ~ Beer".format(a = a), command = beer_cmd)
- beer_button.place(x = 0 , y = 120, width = 100)
- paper_button = Button(menu, text = "{a}2 ~ Paper".format(a = a), command = paper_cmd)
- paper_button.place(x = 0 , y = 150, width = 100)
- cookies_button = Button(menu, text = "{a}2 ~ Cookies".format(a = a), command = cookies_cmd)
- cookies_button.place(x = 120 , y = 0, width = 100)
- scissors_button = Button(menu, text = "{a}4 ~ Scissors".format(a = a), command = scissors_cmd)
- scissors_button.place(x = 120, y = 30, width = 100)
- socks_button = Button (menu, text = "{a}2 ~ Socks".format(a = a), command = socks_cmd)
- socks_button.place(x = 120, y = 60, width = 100)
- tape_button = Button (menu, text = "{a}5 ~ Tape".format(a = a), command = tape_cmd)
- tape_button.place(x = 120, y = 90, width = 100)
- lamp_button = Button(menu, text = "{a}25 ~ Lamp".format(a = a), command = lamp_cmd)
- lamp_button.place(x = 120, y = 120, width= 100)
- headphones_button = Button(menu, text = "{a}90 ~ Headphones".format(a = a), command = headphones_cmd)
- headphones_button.place(x = 120, y = 150, width = 100)
- toaster_button = Button(menu, text = "{a}50 ~ Toaster".format(a = a), command = toaster_cmd)
- toaster_button.place(x = 240, y = 0, width = 100)
- vinegar_button = Button(menu, text = "{a}10 ~ Vinegar".format(a = a), command = vinegar_cmd)
- vinegar_button.place(x = 240, y = 30, width = 100)
- rice_button = Button(menu, text = "{a}14 ~ Rice".format(a = a), command = rice_cmd)
- rice_button.place(x = 240, y = 60, width = 100)
- icecream_button = Button(menu, text = "{a}5 ~ Ice Cream".format(a = a), command = ice_cream_cmd)
- icecream_button.place(x = 240, y = 90, width = 100)
- salt_button = Button(menu, text = "{a}4 ~ Salt".format(a = a), command = salt_cmd)
- salt_button.place(x = 240, y = 120, width = 100)
- paper_towels = Button(menu, text = "{a}5 ~ Paper Towels".format(a = a), command = paper_towels_cmd)
- paper_towels.place(x = 240, y = 150, width = 100)
- menu.mainloop()
- # -- Framework -- #
- root = Tk()
- root.geometry("450x200+500+350") # W x H + X + Y
- root.attributes("-topmost", True)
- root.title("Shopping")
- 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)
- Label_pay = Label(root, text = "Pay : ")
- Label_pay.config(font=("Courier",15))
- Label_pay.place(x = 200 , y = 100)
- #Entry_List = Entry(root)
- #Entry_List.place(x = 0 , y = 30, width = 200)
- # -- Menu Window -- #
- Button_List = Button(root, text = "Menu", command = menu)
- Button_List.place( x = 0, y = 30, width = 100)
- Button_pay = Button(root, text = "Pay", command = Payment_menu)
- Button_pay.place(x = 170, y = 140, width = 150)
- os.system("title Shopping Console")
- cart_menu()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement