Radio Buttons
from tkinter import * def sel(): selection = "You selected the option " + str(var.get()) label.config(text = selection) def sel2(): selection = "You selected the option " + str(var2.get()) label2.config(text = selection) root = Tk() var = IntVar() g1_1 = Radiobutton(root, text="Group1 Option 1", variable=var, value=1,command=sel) g1_1.pack(side=TOP) g1_2 = Radiobutton(root, text="Group1 Option 2", variable=var, value=2,command=sel) g1_2.pack(side=TOP) g1_3 = Radiobutton(root, text="Groups1 Option 3", variable=var, value=3,command=sel) g1_3.pack(side=TOP) label = Label(root, text="Your selection will appear here") label.pack(side=TOP) var2 = IntVar() g2_1 = Radiobutton(root, text="Group1 Option 1", variable=var2, value=10,command=sel2) g2_1.pack(side=TOP) g2_2 = Radiobutton(root, text="Group1 Option 2", variable=var2, value=20,command=sel2) g2_2.pack(side=TOP) g2_3 = Radiobutton(root, text="Groups1 Option 3", variable=var2, value=30,command=sel2) g2_3.pack(side=TOP) label2 = Label(root, text="Your second selection will appear here") label2.pack(side=TOP) root.mainloop()
Checkboxes
from tkinter import * from tkinter import messagebox def selch1(): selection = "Music is " + str(chvar1.get()) label.config(text = selection) def selch2(): selection = "Video is " + str(chvar2.get()) label.config(text = selection) base = Tk() chvar1 = IntVar() chvar2 = IntVar() ch1 = Checkbutton(base, text = "Music", variable = chvar1, \ onvalue = 1, offvalue = 0, height=5, \ width = 20, command = selch1) ch2 = Checkbutton(base, text = "Video", variable = chvar2, \ onvalue = 1, offvalue = 0, height=5, \ width = 20, command = selch2) ch1.pack() ch2.pack() label = Label(base, text="Your selection will appear here") label.pack(side=BOTTOM) base.mainloop()