homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Minor enhancements to Variable class
Type: Stage:
Components: Tkinter Versions: Python 2.4
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: loewis Nosy List: loewis, reowen, rhettinger
Priority: normal Keywords: patch

Created on 2003年07月01日 00:18 by reowen, last changed 2022年04月10日 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkdiff reowen, 2003年07月01日 00:18 diff -c originalTkinter.py newTkinter.py >tkdiff
tkdiff2 reowen, 2003年07月01日 17:30 diff -c originalTkinter.py newTkinter2.py > tkdiff2
Messages (4)
msg44172 - (view) Author: Russell Owen (reowen) Date: 2003年07月01日 00:18
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
msg44173 - (view) Author: Russell Owen (reowen) Date: 2003年07月01日 17:30
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).
msg44174 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2004年12月20日 03:53
Logged In: YES 
user_id=80475
Martin, do you have any thoughts on this one?
msg44175 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006年06月17日 09:15
Logged In: YES 
user_id=21627
Thanks for the patch. Committed as r46998.
History
Date User Action Args
2022年04月10日 16:09:34adminsetgithub: 38752
2003年07月01日 00:18:28reowencreate

AltStyle によって変換されたページ (->オリジナル) /