Reputation: 3
I have the following codes for my radio buttons and this is for my full menu programming project with tkinter:
from tkinter import *
from time import sleep
class SchoolCampMenuGUI:
def __init__(self,parent):
#------------------------------Layout Of Menu------------------------------------------#
Top=Frame(parent,bg="white")
Top.pack(side=TOP) #frame for title School Camp Menu
lblTitle=Label(Top,font=('New York Times',15),text="\t\tSchool Camp Menu\t\t\n(Please choose 1 breakfast,lunch and dinner and below 8700KJ) ")
lblTitle.pack() #setting fonts and size
f4=Label(borderwidth=3,relief=SUNKEN)
f4.pack(side=BOTTOM,fill=X)
f1=Label(borderwidth=3,relief=SUNKEN,bg="white")
f1.pack(side=LEFT) #first label for Breakfast
f2=Label(borderwidth=3,relief=SUNKEN,bg="white")
f2.pack(side=RIGHT) #second label for Lunch
f3=Label(borderwidth=3,relief=SUNKEN,bg="white")
f3.pack() #third label for dinner
def onclick1():
r.set(None)
q.set(None)
v.set(None)
def clear():
sleep(0.5)
f4.configure(text="")#define the definition of RESET button all value set to None to reselect choices and clears all calculations.
b1=Button(f4,text="RESET",width=8,bg="red",command=lambda:[onclick1(),clear()])#calling the combined function
b1.pack(side=RIGHT)
def total():
total=int(v.get())+int(r.get())+int(q.get())
f4.configure(text="Your Current Total Is: "+total+" KJs.")
r=StringVar()
v=StringVar()
q=StringVar()
r.set(0)
v.set(0)
q.set(0)
#--------------------------------------Lunch--------------------------------------#
lblMeal=Label(f3,text="Lunch",font=('arial',14,'bold'),bg="white")
lblMeal.pack()
rb1=Radiobutton(f3,text="Chicken Burgers",variable=r,font=('arial',12,'bold'),value=1180,bg="white",command=total)
rb1.pack(anchor=W)
rb2=Radiobutton(f3,text="Chicken Curry and Rice",variable=r,font=('arial',12,'bold'),value=1800,bg="white",command=total)
rb2.pack(anchor=W)
rb3=Radiobutton(f3,text="Teriyaki Chicken Sushi *Gluten Free",variable=r,font=('arial',12,'bold'),value=1730,fg="violet",command=total)
rb3.pack(anchor=W)
rb4=Radiobutton(f3,text="Caprese Panini *Gluten Free",variable=r,font=('arial',12,'bold'),value=2449,fg="violet",command=total)
rb4.pack(anchor=W)
rb5=Radiobutton(f3,text="Vegetable Risotto *Vegetarian",variable=r,font=('arial',12,'bold'),value=1432,fg="blue",command=total)
rb5.pack(anchor=W)
rb6=Radiobutton(f3,text="Gourmet Vegetable Pizza *Vegetarian",variable=r,font=('arial',12,'bold'),value=1463,fg="blue",command=total)
rb6.pack(anchor=W)
#----------------------------------Breakfast----------------------------------#
Meal=Label(f1,text="Breakfast",font=('arial',14,'bold'),bg="white")
Meal.pack()
rb7=Radiobutton(f1,text="Bacon and Egg Muffin",variable=v,font=('arial',12,'bold'),value=1240,bg="white",command=total)
rb7.pack(anchor=W)
rb8=Radiobutton(f1,text="Scrambled Eggs & Bake Beans",variable=v,font=('arial',12,'bold'),value=1533,bg="white",command=total)
rb8.pack(anchor=W)
rb9=Radiobutton(f1,text="2 Weet-Bix w/ milk",variable=v,font=('arial',12,'bold'),value=1110,bg="white",command=total)
rb9.pack(anchor=W)
rb10=Radiobutton(f1,text="Pancakes w/ syrup",variable=v,font=('arial',12,'bold'),value=2019,bg="white",command=total)
rb10.pack(anchor=W)
rb11=Radiobutton(f1,text="Bread with jam",variable=v,font=('arial',12,'bold'),value=491,bg="white",command=total)
rb11.pack(anchor=W)
rb12=Radiobutton(f1,text="Cinnamon Roll Doughnuts",variable=v,font=('arial',12,'bold'),value=1130,bg="white",command=total)
rb12.pack(anchor=W)
#----------------------------------dinner-----------------------------------#
Dinner=Label(f2,text="Dinner",font=('arial',14,'bold'),bg="white")
Dinner.pack()
rb13=Radiobutton(f2,text="Spaghetti Bolongnese",variable=q,font=('arial',12,'bold'),value=1523,bg="white",command=total)
rb13.pack(anchor=W)
rb14=Radiobutton(f2,text="Beef Burgers w/ Chips and Salad",variable=q,font=('arial',12,'bold'),value=3620,bg="white",command=total)
rb14.pack(anchor=W)
rb15=Radiobutton(f2,text="Meatball and Butter Bean Stew *Gluten Free",variable=q,font=('arial',12,'bold'),value=1820,fg="violet",command=total)
rb15.pack(anchor=W)
rb16=Radiobutton(f2,text="Roast Beef *Gluten Free",variable=q,font=('arial',12,'bold'),value=2280,fg="violet",command=total)
rb16.pack(anchor=W)
rb17=Radiobutton(f2,text="Creamy Broccoli Gnocchi *Vegetarian",variable=q,font=('arial',12,'bold'),value=2800,fg="blue",command=total)
rb17.pack(anchor=W)
rb18=Radiobutton(f2,text="Vegetable Wellington *Vegetarian",variable=q,font=('arial',12,'bold'),value=2270,fg="blue",command=total)
rb18.pack(anchor=W)
Is there a way to add all values together but not getting them? This is for my school menu project. Any help appreciated. Note: The values are in KJs for food. So far I have all the values but they are just put there, e.g. 11801800, but not adding it up. I used r.get()+v.get() but they don't actually add the values up.
Upvotes: 0
Views: 211
Reputation: 2533
They do add up. Your problem is that r.get() returns a string, not an integer. First convert them, then sum up.
int(r.get()) + int(v.get())
Upvotes: 1