tkinter radiobutton

William Gill noreply at gcgroup.net
Tue Jun 28 11:35:12 EDT 2005


 > or use a custom subclass ...

I had considered extending radiobutton to add whatever properties 
needed, but the net/net is the same, that property must be set using 
methods that trigger on the rb command procedure, or an external (to the 
rb) control variable value.

The radiobutton widget knows if it is selected or unselected, or it 
wouldn't be able to display correctly, but based on what I'm seeing, 
that information is inaccessable to the app.  Instead the app must 
evaluate an associated control variable.  That doesn't make sence to me, 
but even trying to look at the code for the radiobutton class didn't help.

I guess I need to set up an observer on the control variable, or a 
command procedure on the radiobutton (effectively to create my own 
control variable).

I know I can 'slice' my original 4 X 4 matrix vertically, by associating 
a different intVar to each 'column', but I can't figure out how to 
'slice' them horizontally w/o breaking their vertical relationships.


Bill

Peter Otten wrote:
> William Gill wrote:
> 
> 
>>I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep
>>references to them in a 2 dimensional list ( rBtns[r][c] ).  It works
>>fine, and I can even make it so only one button per column can be
>>selected, by assigning each column to an intVar.  In many languages a
>>radiobutton has a property that can be directly read to see if it is
>>selected on unselected.  Tkinter radiobuttons don't seem to have any
>>such property.  Is there any way to look (via the script not the screen)
>>to determine if it is selected?, or can this only be achieved via
>>control variables?
> 
> 
> You can either write a little helper function
> 
> def selected(rbn):
>     return rbn.getvar(rbn["variable"]) == rbn["value"]
> 
> or use a custom subclass of Tkinter.Radiobutton with a 'selected' attribute:
> 
> class Radiobutton(Tkinter.Radiobutton):
>     def __getattr__(self, name):
>         if name == "selected":
>             return self.getvar(self["variable"]) == self["value"]
>         raise AttributeError
> 
> 
> Peter
> 



More information about the Python-list mailing list