tkinter radiobutton

William Gill noreply at gcgroup.net
Tue Jun 28 20:20:45 CEST 2005


I thought the problem was practical, not philosophical, but what do I 
know I'm the one asking for help.

I have radiobuttons arranged in 4 rows of 4 buttons each ( 4 rows and 4 
columns )

The user can select no more than 1 choice in any column, but any number 
in any row.

   Restated:
       columns can have 0 or 1 selection
       rows can have 0,1,2,3, or 4 selections.


Columns can be restricted to 0 or 1 selection through the use of an 
intVar. So we now have 4 intVars (control variables)

The app needs to examine the buttons and aggregate the selections for 
each row, efectively converting columnar information to row information.

one solution:

Create 4 intVars
     Column0 = intVar()
     Column1 = intVar()
     Column2 = intVar()
     Column3 = intVar()

Assign  0, 1, 2, 3 and 4 to values to correspond to the row number.
Row1rb1  =  Radiobutton(self, variable = Column0, value = 1)
Row1rb2  =  Radiobutton(self, variable = Column1, value = 1)
Row1rb3  =  Radiobutton(self, variable = Column2, value = 1)
Row1rb4  =  Radiobutton(self, variable = Column3, value = 1)
Row2rb1  =  Radiobutton(self, variable = Column0, value = 2)
Row2rb2  =  Radiobutton(self, variable = Column1, value = 2)
…
…
Row4rb4  =  Radiobutton(self, variable = Column3, value = 4)

to 'read' the user's response:

Loop through the 4 intVars 4 times; compare their value to the value for 
the row being processed; if they are the same bitor a value to a 
rowVariable i.e. convert the column information (intVar values) to row 
information.


Bill



Peter Otten wrote:
> William Gill wrote:
> 
> 
>>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 guessed you wanted to solve a practical problem, but the thoughts
> expressed above suggest, err, philosophical qualms. So, for the sake of the
> argument and since we both don't know the implementation details, be it in
> C or TCL, let's assume that the individual radiobuttons do *not* /know/
> whether they are selected or not but instead compare their associated
> 'variable' with their 'value' every time they are /asked/ to draw
> themselves. That would avoid duplicate state and require only log N instead
> of N bits. Wouldn't that be an elegant implementation, at least in theory?
> 
> So why bother about the layers below when you have all the information to
> write code that works?
> 
> Peter
> 
> 



More information about the Python-list mailing list