Здесь вам не нужна лямбда (в общем, лямбда должна быть очень редкой).Вам нужна только одна функция, чтобы получить все данные, выполнить расчеты и обновить метку.Например:
from tkinter import *
myGui = Tk()
myGui.geometry('450x450+200+200')
myGui.title('Auto Sweet Dispenser')
mysweets_price_list = {1 :9.00,
2 :7.50,
} # dict for the sweet prices
def calculate():
b = v.get( ) # get the value of v set
cost=mysweets_price_list[b] #price
q = int(spinbox1.get()) # get quantity.
final_price = cost * q # final price to be displayed
price.set(final_price)
v =IntVar(value=1) # set initial value to 1
price = IntVar()
Label(myGui,text = 'Choose your sweets',font = 14, fg ='brown').place(x=140,y=55)#grid(row=3,column=10,sticky = 'e')
Radiobutton(myGui,text = 'Mints',variable = v, value = 1, command = calculate).place(x= 160, y = 100)
Radiobutton(myGui,text = 'Nut log',variable = v, value = 2, command = calculate).place(x= 160, y = 120)
Label(myGui,text = 'Select Quantity',font = 12, fg ='brown').place(x=160,y=160)#grid(row=3,column=10,sticky = 'e')
Label(myGui,textvariable = price ,font = "Times 14 bold",width = 14, fg ='white', bg= 'blue' ,relief = RAISED).place(x=160,y=220)#grid(row=3,column=10,sticky = 'e')
spinbox1 = Spinbox(myGui,from_=1,to = 6,command = calculate, state = NORMAL)
spinbox1.place(x=160,y=180)
calculate() # do the calculation at boot
myGui.mainloop()
Также очень важно знать, что если вы делаете name = Widget().place()
, тогда имя устанавливается на None
и бесполезно.Вам нужно сделать
name = Widget()
name.grid() # or pack() or place()
или
Widget().grid() # or pack() or place()
Не смешивайте эти 2 стиля!Стиль 2-х линий гораздо лучше, и то, что мы обычно используем.