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.

Title: tkinter: add _get_master() and use it consistently
Type: enhancement Stage: needs patch
Components: Tkinter Versions: Python 3.5
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.

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

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 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.
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 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