[Tkinter-discuss] FocusOut not working as expected - tix broken?

mkieverpy at tlink.de mkieverpy at tlink.de
Sun Oct 7 20:53:21 CEST 2012


Hello Michael,

I'm back and tested a bit more.
I updated to standard packages (debian wheezy) python 3.2
tcl/tk 8.5 tix 8.4.3 to avoid any problems with who is using
who. I then expanded your test program to emulate my configuration
and what I want to implement. There I noticed that it's not
a tix problem at all, but standard tcl/tk focus behaves the same.
Here's the program:

-----------------------------------------------
import tkinter

root = tkinter.Tk()
f = tkinter.Frame(root)
f.pack(fill='both', expand=1)
tkinter.Button(f, text='foo').pack()

f2 = tkinter.Frame(root)
f2.pack(fill='both')
tkinter.Button(f2, text='bar').pack()

def on_key(event):
    print('key')
def on_focus_out(event):
    print('focus out')
    f.focus_set()
f.focus_set()
f.bind('<Key>', on_key)
f.bind('<FocusOut>', on_focus_out)

root.mainloop()
-----------------------------------------------

The problem is when I use the 'Tab' key to move
the focus. The first 'Tab' moves the focus
to the 'foo' button. 'f' no longer gets key events
but does not get the focus out event either.
The next 'Tab' moves the focus to the 'bar' button,
'f' gets the focus out event and key events arrive again
after I do 'focus_set'.
So it looks like tk standard behaviour. Can I get what I want?
In my program it's a mouse click that can move
the focus away. So tweaking or disabling 'Tab' is not a solution.

Regards,
Matthias Kievernagel


More information about the Tkinter-discuss mailing list