473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Tkinter: tkButtonDown, tkButtonEnter, tkButtonInvoke, tkButtonLeave,tkButtonUp

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. 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 ...

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.

Best regards,
Aki-
Sep 1 '08 #1
8 2980
On Mon, Sep 1, 2008 at 7:45 PM, akineko <ak*****@gmail.comwrote:
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
Sep 2 '08 #2
On Sep 1, 5:52 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
Are you trying to simulate clicks ? You should be doing it using
event_generate, more below.
Actually, I was trying to implement a "sticky" button.
(Button Release is done later by another event)

I already tried event_generate.
It worked as far as I didn't touch other widgets.
But somehow it failed to work if event_generate is called after other
widgets are activated.
You should expect them to be totally removed from Tkinter actually.
Sad to hear that. Controlling the button behaviour explicitly may not
be a common thing to do but it is still necessary thing to do. But you
gave me enough insights.

Aki-
Sep 2 '08 #3
On Mon, Sep 1, 2008 at 10:09 PM, akineko <ak*****@gmail.comwrote:
On Sep 1, 5:52 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
>Are you trying to simulate clicks ? You should be doing it using
event_generate, more below.

Actually, I was trying to implement a "sticky" button.
(Button Release is done later by another event)

I already tried event_generate.
It worked as far as I didn't touch other widgets.
But somehow it failed to work if event_generate is called after other
widgets are activated.
>You should expect them to be totally removed from Tkinter actually.

Sad to hear that. Controlling the button behaviour explicitly may not
be a common thing to do but it is still necessary thing to do. But you
gave me enough insights.
This is an illusion you have, calling those methods are not the way
for explicitly controlling button's behavior, not more than generating
proper events. The explicit way is to not use a button, instead
(ab)use Canvas.
>
Aki-
--
http://mail.python.org/mailman/listinfo/python-list


--
-- Guilherme H. Polo Goncalves
Sep 2 '08 #4
On Sep 1, 6:34 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
This is an illusion you have, calling those methods are not the way
for explicitly controlling button's behavior, not more than generating
proper events. The explicit way is to not use a button, instead
(ab)use Canvas.
Some of my custom widgets used Canvas.
When I designed the "sticky" button widget, I briefly considered use
of Canvas but I rejected because the one I wanted is nothing but
Button (except "sticky" behaviour).
I understand that use of Canvas provides greater flexibility but I
felt it was over-kill.
Your insights are very helpful for me and other people when designing
a custom widget.

Aki-
Sep 2 '08 #5
On Mon, Sep 1, 2008 at 11:01 PM, akineko <ak*****@gmail.comwrote:
On Sep 1, 6:34 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
>This is an illusion you have, calling those methods are not the way
for explicitly controlling button's behavior, not more than generating
proper events. The explicit way is to not use a button, instead
(ab)use Canvas.

Some of my custom widgets used Canvas.
When I designed the "sticky" button widget, I briefly considered use
of Canvas but I rejected because the one I wanted is nothing but
Button (except "sticky" behaviour).
Can you clarify what is this "sticky" behavior ? Are you referring to
a toggle button ? If yes, then you might be after a simple
Checkbutton:

checkbutton = Tkinter.Checkbutton(indicatoron=False, text='test')
I understand that use of Canvas provides greater flexibility but I
felt it was over-kill.
Your insights are very helpful for me and other people when designing
a custom widget.

Aki-
--
http://mail.python.org/mailman/listinfo/python-list


--
-- Guilherme H. Polo Goncalves
Sep 2 '08 #6
On Sep 1, 8:28 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
Can you clarify what is this "sticky" behavior ? Are you referring to
a toggle button ? If yes, then you might be after a simple
Checkbutton:

checkbutton = Tkinter.Checkbutton(indicatoron=False, text='test')
I wouldn't spend days to create a custom widget to mimick the
Checkbutton ;-)

I don't need to describe the detail but once the button was pressed
for a bit while, a command is sent through communication.
The button is left being ButtonDown ("sticky") until an
acknowledgement is sent back through communication.
This is a way to let the user know the action was acknowledged at
another end.

I think probably very few people needs such widget.

Aki-

Sep 2 '08 #7
On Tue, Sep 2, 2008 at 12:44 AM, akineko <ak*****@gmail.comwrote:
On Sep 1, 8:28 pm, "Guilherme Polo" <ggp...@gmail.comwrote:
>Can you clarify what is this "sticky" behavior ? Are you referring to
a toggle button ? If yes, then you might be after a simple
Checkbutton:

checkbutton = Tkinter.Checkbutton(indicatoron=False, text='test')

I wouldn't spend days to create a custom widget to mimick the
Checkbutton ;-)

I don't need to describe the detail but once the button was pressed
for a bit while, a command is sent through communication.
The button is left being ButtonDown ("sticky") until an
acknowledgement is sent back through communication.
This is a way to let the user know the action was acknowledged at
another end.

I think probably very few people needs such widget.
Did you even try creating a checkbutton with indicatoron=False ? You
could get surprised.
>
Aki-

--
http://mail.python.org/mailman/listinfo/python-list


--
-- Guilherme H. Polo Goncalves
Sep 2 '08 #8
On Sep 2, 5:46 am, "Guilherme Polo" <ggp...@gmail.comwrote:
Did you even try creating a checkbutton with indicatoron=False ? You
could get surprised.
I didn't. My perception of checkbutton was a button with a check.
So, I tried as you suggested.
Yes, you are right. It is almost what I wanted (sticky behaviour).
By ignoring the ButtonRelease and Leave events, yes, it can perfectly
meet my requirements.
As checkbutton has deselect() method, this is a better approach, I
have to admit.

Thank you for showing me the correct way to implement.

Aki-
Sep 2 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
2
by: Paul A. Wilson | last post by:
I'm new to Tkinter programming and am having trouble creating a reusable button bar... I want to be able to feed my class a dictionary of button names and function names, which the class will make....
7
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of...
2
by: codecraig | last post by:
Hi, I was reading through the Tkinter tutorial at http://www.pythonware.com/library/tkinter/introduction/index.htm ...and it mentions that by doing, from Tkinter import * you have access to...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.