[Patches] [ python-Patches-763580 ] Minor enhancements to Variable class

SourceForge.net noreply@sourceforge.net
Sun, 13 Jul 2003 08:33:20 -0700


Patches item #763580, was opened at 2003-06-30 19:18
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=763580&group_id=5470

Category: Tkinter
>Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Russell Owen (reowen)
Assigned to: Nobody/Anonymous (nobody)
Summary: Minor enhancements to Variable class

Initial Comment:
Here are two enhancements to the Variable class (and subclasses):

1) Variables now have a "name" argument. This works just like the name argument on almost every other Tkinter class. Its primary purpose is to allow the user to create a new Tkinter Variable given its tk name. 

Justification: at present there is no reasonable way to do this. One can create a new Tkinter Variable and then assign its name property, but that relies on knowing about internals and it has the ugly side effect of creating an unused tk variable

I admit that setvar and getvar can be used to work around the problem, but sometimes it's nicer to use a Tkinter Variable and often it's not convenient to pass the original Variable around to where it's needed.

One can get an original Tkinter widget back again given the corresponding tk widget's name. It's time to allow this for Tkinter Variables (and tkFont.Font objects, but that's a separate issue I submitted as a bug report with associated suggested simple fix).

2) Variables now have a "value" argument to specify the initial value. This shortens:
  avar = StringVar()
  avar.set("desired value")
to:
  avar = StringVar("desired value")

Justification: it's useful. It's also harmless in that it will not break any existing code. I think one can even do something like this in tcl (i.e. define a variable and set it at the same time) and it's certainly a normal thing to do in Python itself.

-- Russell

----------------------------------------------------------------------

Comment By: Russell Owen (reowen)
Date: 2003-07-01 12:30

Message:
Logged In: YES 
user_id=431773

Replacement patch. The difference is what to do if value is supplied and the variable already exists (not something existing users would ever see unless they were doing nasty stuff directly in tcl).  The old version treated value as an initial value, this new version always honors value if it is specified. I think this will be less surprising to the user (in those rare cases where it matters).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=763580&group_id=5470