Tkinter: tkButtonDown, tkButtonEnter, tkButtonInvoke, tkButtonLeave, tkButtonUp

akineko akineko at
Tue Sep 2 00:45:19 CEST 2008

Hi everyone,

This is a memorandum so that other people can share the info.

The following methods are declared in the Tkinter Button class.
tkButtonDown(), tkButtonEnter(), tkButtonInvoke(), tkButtonLeave(),
However, they are not working, when you try, you will get:

_tkinter.TclError: invalid command name "tkButtonLeave"

The bindings in the Tkinter are mapping them to non-existing tk
I needed to use the method badly and I couldn't find any clear
solution for this. So, I spent time to solve this.

tkButtonLeave(), for example, is declared as follows: line 2005 of 3759
    def tkButtonLeave(self, *dummy):'tkButtonLeave', self._w)

Now, in the Tk source distribution, I found the following:
# Commands provided by Tk without official support.  Use them at your
# own risk.  They may change or go away without notice.

namespace eval ::tk::unsupported {

    # Map from the old global names of Tk private commands to their
    # new namespace-encapsulated names.

    variable PrivateCommands
    array set PrivateCommands {
    tkButtonAutoInvoke      ::tk::ButtonAutoInvoke
    tkButtonDown            ::tk::ButtonDown
    tkButtonEnter           ::tk::ButtonEnter
    tkButtonInvoke          ::tk::ButtonInvoke
    tkButtonLeave           ::tk::ButtonLeave
    tkButtonUp          ::tk::ButtonUp
... snip ...

This seems suggesting that the Tkinter bindings are binding obsolete
tk methods.
And, the method should be called seems ::tk::ButtonLeave, instead.

I placed the following into my Tkinter code and it worked.'::tk::ButtonLeave', self.btn._w)

(1) tkButtonDown, tkButtonEnter, tkButtonInvoke, tkButtonLeave,
tkButtonUp are not working.
(2) Bindings are not correct
(2) Workaround is call correct tk methods directly

I hope future Tkinter will be corrected so that the methods are
available as documented.

Best regards,

More information about the Python-list mailing list