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

Problem with Checkbutton and duplicate last name components #73588

Closed
terryjreedy opened this issue Jan 31, 2017 · 4 comments
Closed

Problem with Checkbutton and duplicate last name components #73588

terryjreedy opened this issue Jan 31, 2017 · 4 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 29402
Nosy @terryjreedy, @serhiy-storchaka
Files
  • tkinter-checkbutton-unique-variables.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = None
    created_at = <Date 2017-01-31.21:34:54.653>
    labels = ['3.7', 'expert-tkinter', 'type-bug', 'library']
    title = 'Problem with Checkbutton and  duplicate last name components'
    updated_at = <Date 2017-03-03.20:52:20.440>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2017-03-03.20:52:20.440>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Tkinter']
    creation = <Date 2017-01-31.21:34:54.653>
    creator = 'terry.reedy'
    dependencies = []
    files = ['46696']
    hgrepos = []
    issue_num = 29402
    keywords = ['patch', '3.6regression']
    message_count = 3.0
    messages = ['286552', '286611', '288926']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29402'
    versions = ['Python 3.6', 'Python 3.7']

    @terryjreedy
    Copy link
    Member Author

    Report and code from George Trojan on python-list.

    import tkinter
    
    class GUI(tkinter.Tk):
        def __init__(self):
            tkinter.Tk.__init__(self)
            frame = tkinter.Frame(self)
            for tag in ('A', 'B'):
                w = tkinter.Checkbutton(frame, text=tag)
                w.pack(side='top', padx=10, pady=10)
                print(w)
            frame.pack(side='top')
            frame = tkinter.Frame(self)
            for tag in ('C', 'D'):
                w = tkinter.Checkbutton(frame, text=tag)
                w.pack(side='top', padx=10, pady=10)
                print(w)
            frame.pack(side='top')
    
    gui = GUI()
    gui.mainloop()

    In 3.5, each Checkbutton has unique last name component.
    .2028654224384.2028654606600
    .2028654224384.2028654608224
    .2028654606656.2028654606824
    .2028654606656.2028654608336
    Clicking any box checks or unchecks exactly that box.

    In 3.6, last name components are duplicated
    .!frame.!checkbutton
    .!frame.!checkbutton2
    .!frame2.!checkbutton
    .!frame2.!checkbutton2
    Clicking any box checks or unchecks both button with 'same name'.

    I verified that the _w strings passed in tk.call are the full unique names.

    MRAB reported that adding a tk variable attribute fixed the problem. I notice that Brian Oakley said the same thing in the similar issue bpo-25684, though that is marked for 2.7 and 3.5 also.

    @terryjreedy terryjreedy added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Jan 31, 2017
    @serhiy-storchaka
    Copy link
    Member

    The variable option of the checkbutton widget specifies the name of a global variable to set to indicate whether or not this button is selected. It defaults to the name of the button within its parent (i.e. the last element of the button window's path name).

    There are two workarounds: specify either name or variable arguments explicitly.

    There can be similar issues with other widgets.

    @serhiy-storchaka serhiy-storchaka added stdlib Python modules in the Lib dir topic-tkinter labels Feb 1, 2017
    @serhiy-storchaka serhiy-storchaka self-assigned this Mar 3, 2017
    @serhiy-storchaka
    Copy link
    Member

    Here is a sample patch that makes implicit variables for checkbuttons unique. This is one of ways to solve this issue.

    But I'm not sure that this issue needs to be solved at all. In real applications Checkbutton() is called with the variable argument, otherwise it would be not very useful. Only sample code can call Checkbutton() without the variable argument.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 25, 2022
    …tton.
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Sep 25, 2022
    …tton.
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    @serhiy-storchaka
    Copy link
    Member

    PR #97547 slightly differs from the initial patch. It makes the last element of the name unique by default instead of making the checkbutton variable. If you implicitly specify the same name argument for different checkbuttons, they will share the state.

    ttk.Checkbutton does not have such problem, because it uses the full name as the variable name, it is always unique.

    serhiy-storchaka added a commit that referenced this issue Sep 27, 2022
    …H-97547)
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 27, 2022
    …tton. (pythonGH-97547)
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    (cherry picked from commit adbed2d)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 27, 2022
    …tton. (pythonGH-97547)
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    (cherry picked from commit adbed2d)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    miss-islington added a commit that referenced this issue Sep 27, 2022
    …H-97547)
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    (cherry picked from commit adbed2d)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    miss-islington added a commit that referenced this issue Sep 27, 2022
    …H-97547)
    
    Previously, checkbuttons in different parent widgets could have the same
    short name and share the same state if arguments "name" and "variable" are
    not specified. Now they are globally unique.
    (cherry picked from commit adbed2d)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants