blob: eeddb23f15030886b1e50a6014c1d28dcd806f72 [file] [log] [blame]
Guido van Rossum35820f71994-10-07 09:55:26 +00001from Tkinter import *
2
Tim Peters182b5ac2004-07-18 06:16:08 +00003# This is a demo program that shows how to
4# create radio buttons and how to get other widgets to
5# share the information in a radio button.
6#
7# There are other ways of doing this too, but
Guido van Rossum35820f71994-10-07 09:55:26 +00008# the "variable" option of radiobuttons seems to be the easiest.
9#
10# note how each button has a value it sets the variable to as it gets hit.
11
12
13class Test(Frame):
14 def printit(self):
Collin Winter6f2df4d2007-07-17 20:59:35 +000015 print("hi")
Guido van Rossum35820f71994-10-07 09:55:26 +000016
17 def createWidgets(self):
18
Tim Peters182b5ac2004-07-18 06:16:08 +000019 self.flavor = StringVar()
20 self.flavor.set("chocolate")
Guido van Rossum35820f71994-10-07 09:55:26 +000021
Tim Peters182b5ac2004-07-18 06:16:08 +000022 self.radioframe = Frame(self)
23 self.radioframe.pack()
Guido van Rossum35820f71994-10-07 09:55:26 +000024
Tim Peters182b5ac2004-07-18 06:16:08 +000025 # 'text' is the label
26 # 'variable' is the name of the variable that all these radio buttons share
27 # 'value' is the value this variable takes on when the radio button is selected
28 # 'anchor' makes the text appear left justified (default is centered. ick)
29 self.radioframe.choc = Radiobutton(
30 self.radioframe, text="Chocolate Flavor",
31 variable=self.flavor, value="chocolate",
32 anchor=W)
33 self.radioframe.choc.pack(fill=X)
Guido van Rossum35820f71994-10-07 09:55:26 +000034
Tim Peters182b5ac2004-07-18 06:16:08 +000035 self.radioframe.straw = Radiobutton(
36 self.radioframe, text="Strawberry Flavor",
37 variable=self.flavor, value="strawberry",
38 anchor=W)
39 self.radioframe.straw.pack(fill=X)
Guido van Rossum35820f71994-10-07 09:55:26 +000040
Tim Peters182b5ac2004-07-18 06:16:08 +000041 self.radioframe.lemon = Radiobutton(
42 self.radioframe, text="Lemon Flavor",
43 variable=self.flavor, value="lemon",
44 anchor=W)
45 self.radioframe.lemon.pack(fill=X)
46
47 # this is a text entry that lets you type in the name of a flavor too.
48 self.entry = Entry(self, textvariable=self.flavor)
49 self.entry.pack(fill=X)
50 self.QUIT = Button(self, text='QUIT', foreground='red',
51 command=self.quit)
52 self.QUIT.pack(side=BOTTOM, fill=BOTH)
Guido van Rossum35820f71994-10-07 09:55:26 +000053
54
55 def __init__(self, master=None):
Tim Peters182b5ac2004-07-18 06:16:08 +000056 Frame.__init__(self, master)
57 Pack.config(self)
58 self.createWidgets()
Guido van Rossum35820f71994-10-07 09:55:26 +000059
60test = Test()
61
62test.mainloop()