Question
I need help adding and subtracting the quantities of the label that holds the subtotal of all the quantities from other items in Python GUI
I need help adding and subtracting the quantities of the label that holds the subtotal of all the quantities from other items in Python GUI tkinter. Then adds to the listbox or subtract from it and remove the item from the listbox.
The output I'm trying to get inside the listbox will look something like " 2 iPhone 11(s) $400 each"
The user will press the add button and it will call the iphone11_add() function command when pressed.
When the user wants to get rid of the item, they will press subtract button and it will subtract from the quantity back to its original state of the iphone11_subtract() button.
What algorithms or variables would I need to add and subtract from the subtotal and that will help add to the subtotal function?
Snippets of my code:
# Button functions for the iPhone 11 quantities
def iphone11_add():
float(iphone11_quant_lbl["text"])
def iphone11_subtract():
float(iphone11_quant_lbl["text"])
#Quantity buttons and label for the iPhone 11 being created
iphone11btquant_subtract = Button(techshop, text = '-', command=iphone11_subtract)
iphone11btquant_subtract.grid(row=101, column=1, padx=0, pady=0, sticky=SW)
iphone11_quant_lbl = Label(techshop, text = '0', font =('Verdana', 10))
iphone11_quant_lbl.grid(row=101, column=1, padx=0, pady=0, sticky=S)
iphone11btnquant_add = Button(techshop, text = '+', command=iphone11_add)
iphone11btnquant_add.grid(row=101, column=1, padx=0, pady=0, sticky=SE)
#Creating the receipt listbox and scrollbar
receiptlbl = Label(techshop, text = 'Receipt', font =('Verdana', 20)).grid(row=95, column=11, padx=20, pady=10, sticky=N+S+W)
#Creating instance of the scrollbar
receiptscrollbar = Scrollbar(techshop)
receiptscrollbar.grid(row=100, rowspan=10, column=12, sticky=N+S+W)
#Creating instance of the listbox
receiptbox = Listbox(techshop)
receiptbox.grid(row=100, rowspan=10, column=11, padx=10, sticky=N+S+W)
#Displaying the listbox and scrollbar
receiptbox.config(yscrollcommand=receiptscrollbar.set)
receiptscrollbar.config(command=receiptbox.yview)
#Subtotal
subtotal_lbl = Label(techshop, text = 'Subtotal:', font =('Verdana', 11))
subtotal_lbl.grid(row=110, column=11, sticky=W)
subtotal = Label(techshop, text = '$X.XX', font =('Verdana', 11)) #This holds all the information in the subtotal of all items added.
subtotal.grid(row=110, column=12, sticky=W)
The GUI of the program:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started