Tkinter: tkButtonDown, tkButtonEnter, tkButtonInvoke, tkButtonLeave, tkButtonUp

Guilherme Polo ggpolo at gmail.com
Mon Sep 1 20:52:39 EDT 2008


On Mon, Sep 1, 2008 at 7:45 PM, akineko <akineko at gmail.com> wrote:
> 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(),
> tkButtonUp()
> 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
> methods.
> I needed to use the method badly and I couldn't find any clear
> solution for this.

Are you trying to simulate clicks ? You should be doing it using
event_generate, more below.

> So, I spent time to solve this.
>
> tkButtonLeave(), for example, is declared as follows:
>
> Tkinter.py line 2005 of 3759
>    def tkButtonLeave(self, *dummy):
>        self.tk.call('tkButtonLeave', self._w)
>
> Now, in the Tk source distribution, I found the following:
> unsupported.tcl
> # 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 ...

You are looking at the wrong place, try looking at library/button.tcl
Now, why I said about using event_generate instead of calling those
methods yourself.. tk sets several bindings that varies between
platforms for all these things you are trying to do, and they end up
calling these commands you are trying to call yourself. So, for
instance, given that you have a button:

btn = Tkinter.Button()

to get tk::ButtonEnter called, you should be doing:

btn.event_generate("<Enter>")

and this will work for other those other events too, Leave (Leave),
Button-1 (Down), ButtonRelease-1 (Up), space (Invoke). The remaining
one to talk about is this "ButtonAutoInvoke", which I'm unsure if you
really need it, but, if you do, you could use btn.invoke() supposing
the button has an associated callback which will use "after" to
schedule another btn.invoke().

>
> 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.
>    self.btn.tk.call('::tk::ButtonLeave', self.btn._w)
>
> //
> Summary:
> (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.

You should expect them to be totally removed from Tkinter actually.

>
> Best regards,
> Aki-
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
-- Guilherme H. Polo Goncalves



More information about the Python-list mailing list