[Tutor] tkinter binding issues

Elwin Estle elwin.estle at gmail.com
Wed Oct 19 16:05:17 CEST 2011

I have a couple of bugs in a program I am working on that I can't quite
figure out what is going on.  Both are related to the same lines of code,
and neither really render the program non-functional, they are just
annoying.  Attached is the program, zipped together with a couple of
abbreviated data files it references. I am using python 2.7.

In lines 221, 224, and 226, I use <FocusOut> binding on an entry widget to
validate the data entered.  If the data is invalid, the background color of
the widget is changed to red and the foreground to white.  The callbacks for
these lines are further down in the program starting on lines 302, 317, and
346, respectively.

So, here is the first 'bug'.  In all three of the callback functions, I
added an extra dummy parameter because I kept getting an error message about
the callback wanting two parameters, even though I do not pass any
parameters and don't really need to.  The dummy parameter does nothing and
isn't referenced in the function code.  But without it, why do I get the
error message?

The second bug has to do with the routine starting on line 385, which resets
all the widgets in the input form to their starting values.  If just click
inside the three entry widgets, without inputting any data, the backgrounds
turn red, as they should.  However, when I click the clear form button,
which calls the function on line 385, it doesn't always reset these entry
boxes back to their original state.  It only will do so if the cursor is in
the "clock number" entry box.  If it is in one of the other two boxes, it
will clear all the boxes but that one.

If I comment out the first line of the reset form function (the one that
sets focus back to the clock number entry widget, then all three are
cleared, but the cursor isn't where I want it to be.  I get the idea that
when focus shifts from whatever box the cursor is in, to the 'yes' button in
the tkmessagebox, that it triggers my validation callback and turns the
background red, but shouldn't my clear form function still clear it out?

Thanks in advance for any assistance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111019/96d02fa0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CMM_LOG_PY.zip
Type: application/zip
Size: 4420 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20111019/96d02fa0/attachment.zip>

More information about the Tutor mailing list