Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tkinter: add _get_master() and use it consistently #48593

Open
gpolo mannequin opened this issue Nov 18, 2008 · 8 comments
Open

tkinter: add _get_master() and use it consistently #48593

gpolo mannequin opened this issue Nov 18, 2008 · 8 comments
Labels
stdlib Python modules in the Lib dir topic-tkinter type-feature A feature request or enhancement

Comments

@gpolo
Copy link
Mannequin

gpolo mannequin commented Nov 18, 2008

BPO 4343
Nosy @terryjreedy, @bitdancer, @serhiy-storchaka
Files
  • applying_setup_master.diff
  • setup_master.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2008-11-18.12:39:18.105>
    labels = ['type-feature', 'expert-tkinter']
    title = 'tkinter: add _get_master() and use it consistently'
    updated_at = <Date 2020-12-21.09:22:57.177>
    user = 'https://bugs.python.org/gpolo'

    bugs.python.org fields:

    activity = <Date 2020-12-21.09:22:57.177>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Tkinter']
    creation = <Date 2008-11-18.12:39:18.105>
    creator = 'gpolo'
    dependencies = []
    files = ['12041', '12042']
    hgrepos = []
    issue_num = 4343
    keywords = ['patch', 'needs review']
    message_count = 8.0
    messages = ['76005', '80988', '190634', '190635', '228589', '228611', '248152', '383498']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'gpolo', 'r.david.murray', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'pending'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4343'
    versions = ['Python 3.5']

    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Nov 18, 2008

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

    @gpolo gpolo mannequin added the topic-tkinter label Nov 18, 2008
    @gpolo
    Copy link
    Mannequin Author

    gpolo mannequin commented Feb 2, 2009

    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.

    @merwok merwok added the type-feature A feature request or enhancement label Nov 28, 2010
    @terryjreedy
    Copy link
    Member

    I am still confused about the master/parent business and why required args are documented as optional. (Besides bpo-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 bpo-18131.

    @terryjreedy
    Copy link
    Member

    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.

    @bitdancer
    Copy link
    Member

    Changing status back to 'needs patch' per Terry's comment that the patch needs to be updated (now for 3.5).

    @terryjreedy
    Copy link
    Member

    The new function should be private. I closed bpo-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.

    @terryjreedy terryjreedy changed the title New function in Tkinter.py: setup_master tkinter: add _get_master() and use it consistently Oct 5, 2014
    @terryjreedy
    Copy link
    Member

    Serhiy, have your patches on other issues make this one obsolete, or partially so?

    @serhiy-storchaka
    Copy link
    Member

    I do not think that popping up a root window on first call of Variable() or getboolean() is a good idea. bpo-42630 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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants