i have a have listbox that is bind to itemlistcallback function. i want to create label by clicking on a item in listbox for first time and update it if it was clicked more than once. the result is no matter on what item i click on, only the last label change.
its a receipt system for a restaurant that is going to increase quantity of item by clicking on them.
def itemlistcallback(event):
selection = event.widget.curselection()
if selection:
global rowcount
global itemqty
global itemid
global itemcount
print(rowcount)
rowcount +=1
index = selection[0]
data = event.widget.get(index)
orderitemslist.insert(0,data)
if data[0] not in itemset:
itemid = "itemnamelbl"+str(data[0])
itemcount = "itemcount"+str(data[0])
itemid = Label(orderitemframe, text= data[1], font= ('Helvetica 12 bold'))
itemcount = Label(orderitemframe, text=itemqty, font= ('Helvetica 12 bold'))
itemid.grid(row=rowcount, column=1, padx = 0, pady = 0,sticky='n')
itemcount.grid(row=rowcount, column=0, padx = 0, pady = 0,sticky='n')
itemset.append(data[0])
else:
itemqtyy = itemcount.cget("text")
itemcount.config(text = itemqtyy+1)
else:
pass
itemslist.bind("<<ListboxSelect>>", itemlistcallback)
i’d tried winfo_exists() to check if a widget exist or not, after getting no result, i make a list of what ids added to create a widget.
m k is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.