tkinter radiobutton
William Gill
noreply at gcgroup.net
Mon Jun 27 10:21:29 EDT 2005
>> to determine if it is selected?, or can this only be achieved via
>> control variables?
> The value and variable options for a radiobutton seem to be what
> you're looking for.
Thanks, I knew that, but I was looking for a way to read the
selected/unselected status directly. Using control variables gets a
little messy because of the relationship of the rb matrix. They are
arranged in a 4 X 4 matrix where each column is grouped (via intVars) so
that no more than 1 rb per column can be selected, but each row makes up
the 'status' on one 'item' so any combination of buttons in a row is
acceptable.
One solution I have been contemplating requires setting the value of
each rb to the row number ( 0, 1, 2, or 3 or 1,2,3, or 4 in case I need
to use 0 for 'none selected'), and using one intVar for each column.
Then I would have to loop through all four intVars four times to
determine which radiobuttons are selected in each row. That's what I
mean by messy.
Bill
Eric Brunel wrote:
> On Sat, 25 Jun 2005 19:34:50 GMT, William Gill <noreply at gcgroup.net> 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?
>
>
> The value and variable options for a radiobutton seem to be what you're
> looking for. Here is an example showing how to use them:
>
> ----------------------------------------------------------------
> from Tkinter import *
>
> root = Tk()
> v = StringVar()
> Radiobutton(root, text='foo', value='foo', variable=v).pack()
> Radiobutton(root, text='bar', value='bar', variable=v).pack()
>
> def p():
> print v.get()
>
> Button(root, command=p, text='Print').pack()
>
> root.mainloop()
> ----------------------------------------------------------------
>
> HTH
More information about the Python-list
mailing list