boB Stepp wrote:

> 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?

It looks like the empty string is special. On my (linux) system all buttons 
appear grayed (while a selected button would be black). Any other string 
should give the desired result, probably because every button "thinks" that 
another button is currently selected.

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to