You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
you should not name your class by simply adding a number (like '2' or '3' ...)
or you must give a unique name of your class instance with the 'name=' option in the Label constructor.
To correct the bug:
The naming algorithm should check that the automatically generated name is not already in use.
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, name only gets the __name__ of the __class__ corresponding to the current instance, not the name of the widgets in tkinter, which can be corrected to avoid the above problem.
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: