classification
Title: Add Tkinter.Checkbutton get() and set(value)
Type: Stage:
Components: Tkinter Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: loewis Nosy List: gpolo, loewis, pysquared
Priority: normal Keywords: patch

Created on 2007-08-14 22:38 by pysquared, last changed 2008-06-26 22:43 by gpolo. This issue is now closed.

Files
File name Uploaded Description Edit
Tkinter_cbgetset.diff pysquared, 2007-08-14 22:38
Messages (6)
msg53029 - (view) Author: Graham Horler (pysquared) Date: 2007-08-14 22:38
Add get() and set(value) methods to the Checkbutton class, providing access to the default variable created by Tk.

See man checkbutton(3tk).

The get() and set(value) method names are analogous to those in the Variable class.

When using get() and set(), you do not have to create a XyzVar instance to pass to a Checkbutton's 'variable' attribute.

This is much simpler and more intuitive, and also avoids leaking the default variable.

If you do override the 'variable' attribute, the get() and set(value) also give access to your new variable.

Setting 'onvalue' and 'offvalue' also work as expected.
msg68297 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-06-16 23:44
The checkbutton widget doesn't have get and set commands, so I'm not
sure why you said to look at its man page.

But the idea of not needing to play with SomeVar creation is good, I
like it, but then I would prefer to add it to all the other widgets that
play with it. And it could be a property.
msg68790 - (view) Author: Graham Horler (pysquared) Date: 2008-06-26 16:02
I referred to the man page, as it says this:
 Command-Line Name:-variable ... Defaults to the name of the button 
within its parent.

When you create a Checkbutton widget without giving a variable=SomeVar, 
a default variable is created which Tkinter does not give you easy 
access to.

My patch adds easy access to this default variable.

This is analogous to being able to use an Entry widget without having 
to assign SomeVar to textvariable first.

Yes it could be a property, but Tkinter.py does not use property 
anywhere else, and I am stuck with having to support python 2.1.

What do you mean by "add it to all the other widgets that play with it"?

Thanks
msg68794 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-06-26 16:57
On Thu, Jun 26, 2008 at 1:02 PM, Graham Horler <report@bugs.python.org> wrote:
>
> Graham Horler <grahamh@users.sourceforge.net> added the comment:
>...
> When you create a Checkbutton widget without giving a variable=SomeVar,
> a default variable is created which Tkinter does not give you easy
> access to.

I'm aware of that and that is why everywhere I see Checkbutton being
used I see a explicit variable being created.

> ...
> What do you mean by "add it to all the other widgets that play with it"?
>

I was referring to the other widgets that accepts *variable options.
Ideally I would to prefer to never need to instantiate Variable or any
of its subclasses, adding methods at the correct places. So what I
meant was to add this functionality everywhere it would cause some
benefit, not only for Checkbutton.
msg68803 - (view) Author: Graham Horler (pysquared) Date: 2008-06-26 21:59
> I'm aware of that and that is why everywhere I see Checkbutton
> being used I see a explicit variable being created.

Absolutely the reason for this patch, to get rid of unnecessary code.
What's not to like?

> I was referring to the other widgets that accepts *variable options.
> ... add this functionality everywhere it would cause some
> benefit, not only for Checkbutton.

I'm all for that, just could not find another widget that created an
inaccessible default variable.  Suggestions welcome.
msg68806 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-06-26 22:43
> Graham Horler <grahamh@users.sourceforge.net> added the comment:
>
>> I'm aware of that and that is why everywhere I see Checkbutton
>> being used I see a explicit variable being created.
>
> Absolutely the reason for this patch, to get rid of unnecessary code.
> What's not to like?

You are not getting my point here. What I'm trying to say is: if you
are going to add such code to make it easier to get/set the variable
option value then you better add it to every other widget that
supports a variable option, or a textvariable (*variable in general).
This would make things uniform, you would never need to create a
Variable instance yourself. What I would really hate to see is a
widget that acts like a Variable was created for me, so I can
access/set its value, and others that have the same option but doesn't
allow me that.
And, finally, being explicit is not a bad thing.

>
>> I was referring to the other widgets that accepts *variable options.
>> ... add this functionality everywhere it would cause some
>> benefit, not only for Checkbutton.
>
> I'm all for that, just could not find another widget that created an
> inaccessible default variable.  Suggestions welcome.
>

Radiobutton for example ?
History
Date User Action Args
2008-06-26 22:43:17gpolosetmessages: + msg68806
2008-06-26 21:59:55pysquaredsetmessages: + msg68803
2008-06-26 16:57:37gpolosetmessages: + msg68794
2008-06-26 16:02:26pysquaredsetmessages: + msg68790
2008-06-16 23:44:27gpolosetstatus: open -> closed
resolution: wont fix
messages: + msg68297
nosy: + gpolo
2007-08-14 22:38:20pysquaredcreate