Tcl/Tk widgets and FocusOut not working as expected on linux
Do anyone know why FocusOut event is not working on linux?
I have 1 enabled textbox and 3 disabled combobox. I bind the textbox with FocusOut event where it will call a proc that enables or disabl开发者_JAVA百科es the 3 combobox.
It works perfectly on Windows. However, it doesn't seem to trigger the FocusOut event when this action is done on Linux. One weird thing is that if I click on buttons, FocusOut event seems to be triggered.
Could it be because my combobox are disabled? But why does it work on Windows?
I really hope someone can help me please.
Thanks in advance.
I have observed in the past that some window managers steal the focus temporarily from Tk on each button click before setting it back; I suspect that this has to do with the way that key event handling works, but I am unable to check at the moment (due to being on OSX, where things are different). Because of the complexities involved, I'd suggest that if you bind to <FocusOut>
, you should also check whether you get a <FocusIn>
event shortly after; a little extra delay (e.g., 0.1s) before doing the update of the buttons' disabled status will not hurt.
Or you could hang the code to do the disabling off the entry widget validation engine, perhaps like this:
.e configure -validation focusout -validatecommand doButtonEnableDisable
The validation interface is the same for both the old style entry
and the new style ttk::entry
widgets. It's also supported by spinboxes. Just be aware that you need to return a boolean true from doButtonEnableDisable
or you'll reject the change to the entry, and you should take care to ensure that your code does not produce an error or it will disable itself; the docs list the things to watch out for.
精彩评论