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: Minor revision to the method in Tkinter
Type: enhancement Stage: resolved
Components: Tkinter Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Drew.French, ezio.melotti, gpolo, serhiy.storchaka
Priority: low Keywords: patch

Created on 2012-07-09 08:25 by Drew.French, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkbugfix.py Drew.French, 2012-07-09 08:25 A revised version of the <BaseWidget._setup> method in Tkinter
tkinter_widget_is_none.patch serhiy.storchaka, 2012-12-23 18:55 review
Pull Requests
URL Status Linked Edit
PR 23904 merged serhiy.storchaka, 2020-12-23 06:09
Messages (5)
msg165070 - (view) Author: Drew French (Drew.French) Date: 2012-07-09 08:25
In the <BaseWidget._setup> method, <master> is evaluated as a Boolean (when Tkinter attempts to find a parent for the widget). I think it should really be evaluated against <None>, seeing as that is the default <master> keyword argument value for most widgets. I ran into problems with this when making a container widget class that inherited from the <Canvas>, then implementing the <__len__> magic method. When the length was zero the widget would evaluate as false, which would prevented me from packing widgets inside my container widget.

I attached a revised version of the method.
msg175233 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-09 13:16
Can you provide a patch in diff format?
You can find more information about how to do it on the devguide.
msg175236 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2012-11-09 14:11
Please include a short version of the widget class you mentioned. It must be only long enough to show the issue.
msg178007 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-23 18:55
Here is a patch against 3.4 which contains proposed OP change and a lot of similar changes in different places. I'm not sure that this should be considered as a bug fix and not as an enhancement.

Drew, as a workaround you can implement __bool__() method which returns True for your widget. Or even better, do not make your container sequence-like.
msg383746 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-25 15:04
New changeset bb70b2afe39ad4334a9f3449cddd28149bd628b6 by Serhiy Storchaka in branch 'master':
bpo-15303: Support widgets with boolean value False in Tkinter (GH-23904)
https://github.com/python/cpython/commit/bb70b2afe39ad4334a9f3449cddd28149bd628b6
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59508
2020-12-25 19:48:59serhiy.storchakasetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.10, - Python 3.6
2020-12-25 15:04:29serhiy.storchakasetmessages: + msg383746
2020-12-23 06:09:00serhiy.storchakasetpull_requests: + pull_request22758
2016-07-24 11:04:03serhiy.storchakasetassignee: serhiy.storchaka
type: behavior -> enhancement
versions: + Python 3.6, - Python 3.4
2014-01-09 19:50:06serhiy.storchakasetpriority: normal -> low
2012-12-23 18:55:10serhiy.storchakasetfiles: + tkinter_widget_is_none.patch

versions: + Python 3.4, - Python 2.7
keywords: + patch
nosy: + serhiy.storchaka

messages: + msg178007
stage: needs patch -> patch review
2012-11-09 14:11:36gpolosetmessages: + msg175236
2012-11-09 13:16:40ezio.melottisetnosy: + gpolo, ezio.melotti

messages: + msg175233
stage: needs patch
2012-07-09 08:25:49Drew.Frenchcreate