classification
Title: Minor revision to the method in Tkinter
Type: behavior Stage: patch review
Components: Tkinter Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Drew.French, ezio.melotti, gpolo, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-07-09 08:25 by Drew.French, last changed 2012-12-23 18:55 by serhiy.storchaka.

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
Messages (4)
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.
History
Date User Action Args
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