[Tutor] How to display radiobutton window with no buttons selected?
boB Stepp
robertvstepp at gmail.com
Mon Apr 24 23:41:26 EDT 2017
Win7-64bit, Python 3.6.1
When I run the following code, the radiobutton window initially
displays with *all* buttons apparently selected. However, when the
"Status" button is clicked on, the status is as expected, an empty
string for the checked_radiobutton StringVar().
================================================================================
#!/usr/bin/env python3
import tkinter as tk
root = tk.Tk()
# Report option selected:
def status():
print('You selected the radiobutton: %s' % checked_radiobutton.get())
print()
languages = ('Perl', 'JavaScript', 'PHP', 'Python 2', 'Python 3')
# Create new variable object to keep track of checked radiobutton:
checked_radiobutton = tk.StringVar()
for language in languages:
# Create new radiobutton:
tk.Radiobutton(root, text=language, variable=checked_radiobutton,
value=language).pack(anchor='w')
checked_radiobutton.set('')
tk.Button(root, text='Status', command=status).pack(fill='x')
root.mainloop()
================================================================================
I wish the displayed window to initially display with no button
selected. What am I missing here?
Thanks!
--
boB
More information about the Tutor
mailing list