I'm trying to make a shopping basket/cart which contains items from a dictionary. Dictionary holds item name and its price. The code below displays items from dictionary and multiply quantity to price. There are + and - buttons which should modify the quantity for specific item, but something is wrong with my code and buttons are changing only last item's quantity and won't change the price according to quantity. I hope you can help me. Thanks.
from tkinter import *
def add_qty():
qty = qtity_label.cget('text')
qty += 1
qtity_label.config(text=qty)
print(qty)
def sub_qty():
qty = qtity_label.cget('text')
qty -= 1
qtity_label.config(text=qty)
print(qty)
root = Tk()
shopping_basket = {'nerf': 25.00,
'lego': 10.00,
'ball': 5.00}
row = 0
for item in shopping_basket:
item_name_lbl = Label(root, text=item)
item_name_lbl.grid(column=0, row=row)
qtity_label = Label(root, text=2)
qtity_label.grid(column=5, row=row)
price_lbl = Label(root, text=qtity_label.cget('text')*shopping_basket[item])
price_lbl.grid(column=9, row=row)
sub_qtity_btn = Button(root, text='-', command=sub_qty)
sub_qtity_btn.grid(column=4, row=row)
add_qtity_btn = Button(root, text='+', command=add_qty)
add_qtity_btn.grid(column=6, row=row)
row += 1
root.mainloop()