Ham & Eggs

Checkbutton & Frame, plus actually using and manipulating values in control variables. Check and uncheck the buttons and see the possibilities.

<pre>#Checkbutton_Frame_Label Example for wikipython

#standard set up header code 2 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='white')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight()  
workwindow = str(1024) + "x" + str(768)+ "+" +str(int((scrW-1024)/2)) + "+" +str(int((scrH-768)/2))
top1 = Toplevel(root, bg="light blue")
top1.geometry(workwindow)
top1.title("Top 1 - Workwindow")
top1.attributes("-topmost", 1)  # make sure top1 is on top to start
root.update()                   # but don't leave it locked in place
top1.attributes("-topmost", 0)  # in case you use lower or lift
#exit button - note: uses grid
b3=Button(root, text="Egress", command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________

def cb():
    # send the variables to Idle Shell screen
    print ("Ham is:", var1.get())  # confirmation that our variables
    print ("Eggs is:", var2.get())  # are properly set and available
    print ("Coffee is:", var3.get())
    print ("Toast is:", var4.get())
    var5.set("Your total is: $" + str(var1.get()+var2.get()+var3.get()+var4.get()))
    
#create a frame to put buttons into
f = Frame(top1, relief=RAISED , borderwidth=10, width=60)
f.pack(anchor="s", pady=75, ipadx=15)

var1 = IntVar(0)# set up control variables for each checkbutton
var2 = IntVar(0)
var3 = IntVar(0)
var4 = IntVar(0)
var5 = StringVar()
var5.set("Your total is: $")
#no need to set() control variable - tkinter does it for us with onvalue
c1 = Checkbutton(f, text="Ham  $4", variable=var1, onvalue=4, command= cb)
c1.pack(side=TOP, ipady=2, anchor="w")
c2 = Checkbutton(f, text="Eggs   $3", variable=var2, onvalue=3, command= cb)
c2.pack(side=TOP, ipady=2, anchor="w")
c3 = Checkbutton(f, text="Coffee $1", variable=var3, onvalue=1, command= cb)
c3.pack(side=TOP, ipady=2, anchor="w")
c4 = Checkbutton(f, text="Toast   $2", variable=var4, onvalue=2, command= cb)
c4.pack(side=TOP, ipady=2, anchor="w")
#create a label at the bottom where we can post a running total
Total=Label(top1, relief=SUNKEN, bg="blanched almond", textvariable=var5, padx=20)
Total.pack(side=TOP, ipadx=5, ipady=5, pady=20, anchor="s")

#____________________________
root.mainloop()

</pre>