Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tkinter_radiobuttons_demo.py
- from Tkinter import *
- class RBDemo:
- def __init__(self, win):
- self.v = IntVar()
- #Put the first group of radio buttons in their own frame.
- f1 = Frame(win, borderwidth=3, relief=RAISED)
- rb1 = Radiobutton(f1, text="One", variable=self.v, value=1)
- rb2 = Radiobutton(f1, text="Two", variable=self.v, value=2)
- rb3 = Radiobutton(f1, text="Three", variable=self.v, value=3)
- rb1.pack(anchor=W); rb2.pack(anchor=W); rb3.pack(anchor=W)
- f1.pack(side=LEFT)
- #Button one will be selected by default
- self.v.set(1)
- #Make a second group of radiobuttons in their own frame.
- #The "g" value is default. (Button with "Green" label)
- self.v2 = StringVar()
- f2 = Frame(win, borderwidth=2, relief=SOLID)
- rb4 = Radiobutton(f2, text="Red", variable=self.v2, value="r")
- rb5 = Radiobutton(f2, text="Green", variable=self.v2, value="g")
- rb6 = Radiobutton(f2, text="Blue", variable=self.v2, value="b")
- rb4.pack(anchor=W); rb5.pack(anchor=W); rb6.pack(anchor=W);
- f2.pack(side=RIGHT)
- self.v2.set("g")
- #Make a button that prints what each value is when clicked
- b = Button(win, text="Try This Out!", command=self.clicked)
- b.pack(side=BOTTOM, fill=BOTH, expand=1)
- def clicked(self):
- print "Button Clicked!"
- print "v is:", self.v.get()
- print "v2 is:", self.v2.get()
- print
- root = Tk()
- app = RBDemo(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement