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: Problem with Checkbutton and duplicate last name components
Type: behavior Stage: patch review
Components: Library (Lib), Tkinter Versions: Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: serhiy.storchaka, terry.reedy
Priority: normal Keywords: 3.6regression, patch

Created on 2017-01-31 21:34 by terry.reedy, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
tkinter-checkbutton-unique-variables.patch serhiy.storchaka, 2017-03-03 20:52 review
Messages (3)
msg286552 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-01-31 21:34
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 #25684, though that is marked for 2.7 and 3.5 also.
msg286611 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-01 10:31
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.
msg288926 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-03 20:52
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.
History
Date User Action Args
2022-04-11 14:58:42adminsetgithub: 73588
2019-11-28 07:04:43serhiy.storchakalinkissue38898 superseder
2017-03-03 20:52:20serhiy.storchakasetfiles: + tkinter-checkbutton-unique-variables.patch
keywords: + patch
messages: + msg288926

stage: test needed -> patch review
2017-03-03 15:42:50serhiy.storchakasetassignee: serhiy.storchaka
2017-02-01 10:31:29serhiy.storchakasetmessages: + msg286611
components: + Library (Lib), Tkinter
2017-01-31 21:34:54terry.reedycreate