Need help with moving focus using Tkinter

Richard Kuhns rjkuhns at geetel.net
Thu Dec 5 08:36:07 EST 2002


I recently asked for help about creating a scrolling canvas to hold
multiple frames, and was directed to Pmw.  That's worked out very nicely,
and I really appreciate the pointer.  I've now hit another stumbling
block, though, that I just can't find my way around.  I'm probably
overlooking something very simple, too.

Here goes:  I'm using the scrolling canvas to hold an indefinite number of
1 line frames.  Each frame has 4 entry widgets.  All data entered will be
numeric, so it would be very nice to be able to just use the keypad. 
Therefore I'd like the Enter to shift focus to the next widget on a line
for the first 3 widgets, and then do some extra processing when pressed on
the fourth widget.  It looks to me like I should be binding Enter to
w.tk_focusNext().  When I try that, though, it quietly (and apparently
successfully) does absolutely nothing.

To try to figure out what I'm doing wrong, I wrote the following function
and bound it to the letter 't' (self refers to an instance of a class that
inherits from Frame, btw):

   def hitT(self, event):
        print "+++t was hit:", event
        print "focus is at", self.focus_get()
        self.tk_focusNext()
        print "focus is now at", self.focus_get()

I bound it to 't' using """self.form.bind_all('t', self.hitT)"""

There are no errors, and the output in the xterm I start the form from
shows that focus hasn't moved -- both calls to self.focus_get() return the
same value.  Also, the 't' still appears in the entry widget.  According
to the tkinter reference I downloaded from nmt.edu, this binding should
have replaced the old one since I didn't say 'add="+"'.

I should also note that the Tab key moves focus just like it should, but
Shift-Tab doesn't move the focus backwards.

Any help would be greatly appreciated.

	- Dick
-- 
Richard Kuhns			rjkkuhns at geetel.net




More information about the Python-list mailing list