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: tkinter: add _get_master() and use it consistently
Type: enhancement Stage: needs patch
Components: Tkinter Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: gpolo, r.david.murray, serhiy.storchaka, terry.reedy
Priority: normal Keywords: needs review, patch

Created on 2008年11月18日 12:39 by gpolo, last changed 2022年04月11日 14:56 by admin.

Files
File name Uploaded Description Edit
applying_setup_master.diff gpolo, 2008年11月18日 12:39
setup_master.diff gpolo, 2008年11月18日 12:45
Messages (8)
msg76005 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008年11月18日 12:39
Hi,
I've added a new function called setup_master. 
This function is responsible for returning an usable master to the
caller, or fail and say so. The function is useful for any wrapper
basically, since all them has to set up a master sometime (or maybe
always require a master, but that is not very nice) and will usually do
it half wrong. The half wrong is about relying on _default_root being
available in Tkinter, which is not the case if support for default root
has been disabled.
There are two patches, the first adds the function, the second applies
it self where necessary in Tkinter. The later also adds some new
behaviour in Tkinter, previously Variable class and subclasses wouldn't
work properly without prior creation of a master (there are similar
problems in other parts too).
msg80988 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009年02月02日 20:09
Any chance I can get this in ? I'm using something very similar to test
the ttk wrapper and will also be using in other tests, extensions would
also benefit from it, and old code doesn't get affected to it.
msg190634 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013年06月05日 00:10
I am still confused about the master/parent business and why required args are documented as optional. (Besides #18131, I also discovered that messageboxes usually, but not always, require parent=something passed, to be collected into **options. I need to read more before I can really review and think about applying this.
Why isn't _default_root initialized to something useful instead of None. If it were, _support_default_root would not be needed.
The new function is slightly different from the code it replaces. The main difference I see with Misc.setup is that your code does *not* stash Tk() in _default_root. Since every Tk() call creates a new screen window, I do not see how this is correct.
On the plus side, I believe your patch would fix part of the problem I reported in #18131.
msg190635 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013年06月05日 01:24
After searching through tkinter.py for '_default_root', the patch looks better. The point I missed before is that Tk().__init__(self,...) normally calls _loadtk(self) which installs self as _default_tk if it was None before. So the new function will return the same Tk object each call after the first (unless _default_tk is somehow reset to None.) This also means that the assignment in BaseWidget.setup, "_default_root = Tk()", which the patch deletes, is redundant and misleading, and should go.
I think 'getmaster' or 'get_master' would be a better name than 'setup_master' as setting up a new master is the 2nd backup choice and will happen only once in a session. Most call will get an existing master -- either the one passed in or the once stored as _default_root 
The patch needs to be updated for 3.4 and run with current tests.
msg228589 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014年10月05日 16:25
Changing status back to 'needs patch' per Terry's comment that the patch needs to be updated (now for 3.5).
msg228611 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014年10月05日 18:29
The new function should be private. I closed #18131 as partially a duplicate of this. It has a couple of other suggested wordings for the exception.
I consider the current behavior, in particular the failure of Variable and subclasses when the supposedly optional master is not passed, to be buggy. So I think backporting should be considered when we settle on a patch.
msg248152 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015年08月06日 21:53
Serhiy, have your patches on other issues make this one obsolete, or partially so?
msg383498 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020年12月21日 09:22
I do not think that popping up a root window on first call of Variable() or getboolean() is a good idea. Issue42630 fixed errors in other way. A root window is not automatically created for non-graphic objects (like Variable), instead a RuntimeError with relevant error message is raised.
History
Date User Action Args
2022年04月11日 14:56:41adminsetstatus: pending -> open
github: 48593
2020年12月21日 09:22:57serhiy.storchakasetstatus: open -> pending

messages: + msg383498
2015年08月06日 21:53:09terry.reedysetmessages: + msg248152
2014年10月05日 18:29:50terry.reedysetnosy: + serhiy.storchaka

messages: + msg228611
title: New function in Tkinter.py: setup_master -> tkinter: add _get_master() and use it consistently
2014年10月05日 16:25:31r.david.murraysetversions: + Python 3.5, - Python 3.4
nosy: + r.david.murray

messages: + msg228589

assignee: gpolo ->
stage: commit review -> needs patch
2013年06月05日 01:24:13terry.reedysetmessages: + msg190635
versions: + Python 3.4, - Python 3.2
2013年06月05日 00:10:11terry.reedysetnosy: + terry.reedy
messages: + msg190634
2010年11月28日 05:26:26eric.araujosetkeywords: + needs review
assignee: gpolo
stage: commit review
type: enhancement
versions: + Python 3.2, - Python 3.1, Python 2.7
2009年02月02日 20:10:00gpolosetmessages: + msg80988
versions: + Python 3.1, - Python 3.0
2008年11月18日 12:45:59gpolosetfiles: + setup_master.diff
2008年11月18日 12:45:47gpolosetfiles: - setup_master.diff
2008年11月18日 12:39:36gpolosetfiles: + applying_setup_master.diff
2008年11月18日 12:39:18gpolocreate

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