-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
tkinter widget instance name sometimes duplicated on inherited class #128562
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
Comments
Hello @philrich123 , I've created a PR to try to fix this. It works for the example you mentioned above, but I don't currently guarantee that it will solve all similar problems, as it may have some omissions. In the original code, |
There were possible conflicts if the widget class name ends with a digit.
Thanks @philrich123 for the report and @Xiaokang2022 for the fix. |
Bug report
Bug description:
If you run de following code:
It will produce the following result (only label_1 and label_3 seems to be placed) :

instead of what you expect (the following result) :

Note: This code is using Label for simplicity but it's the same with other widgets !
Explanation:
This is because of automatic generated tkinter widget names:
label_1 name is '.!label'
label_2 name is '.!label2'
label_3 name is '.!label2'
So 'label_2' and 'label_3' has the same widget name.
If you print the 'w.winfo_children()' function just before the 'w.mainloop()', you just get 2 widgets in the list.
The 'label_3' override the 'label_2' because for tkinter they are the same !
To get around this bug:
To correct the bug:
The naming algorithm should check that the automatically generated name is not already in use.
CPython versions tested on:
3.9, 3.13
Operating systems tested on:
Linux, Windows
Linked PRs
The text was updated successfully, but these errors were encountered: