Tk, default event bindings

A

Alexander Fleck

Hi,
do the Tk widgets own default event bindings? In tutorials I' ve seen, that the 'command proc' statement was used to add a procedure to a button event. But the procedure just gets started, when the button is clicked. I thought I have to bind a procedure to a specific event. Does the procedure get bend to a default event when the "command proc" is used?
Alex.
 
H

Hidetoshi NAGAI

From: "Alexander Fleck" <[email protected]>
Subject: Tk, default event bindings
Date: Tue, 11 Oct 2005 18:56:54 +0900
Message-ID: said:
do the Tk widgets own default event bindings?

You can learn the default bindings of each widget with
Tcl/Tk's manual pages.
For example, on Tcl/Tk's man pages, description about default
bindings of button widget is
----------------------------------------------------------------------
DEFAULT BINDINGS
Tk automatically creates class bindings for buttons that
give them default behavior:

[1] A button activates whenever the mouse passes over
it and deactivates whenever the mouse leaves the
button. Under Windows, this binding is only active |
when mouse button 1 has been pressed over the but- |
ton.

[2] A button's relief is changed to sunken whenever
mouse button 1 is pressed over the button, and the
relief is restored to its original value when but-
ton 1 is later released.

[3] If mouse button 1 is pressed over a button and
later released over the button, the button is
invoked. However, if the mouse is not over the
button when button 1 is released, then no invoca-
tion occurs.

[4] When a button has the input focus, the space key
causes the button to be invoked.

If the button's state is disabled then none of the above
actions occur: the button is completely non-responsive.

The behavior of buttons can be changed by defining new
bindings for individual widgets or by redefining the class
bindings.
----------------------------------------------------------------------

Therefore,
In tutorials I' ve seen, that the 'command proc' statement was used
to add a procedure to a button event. But the procedure just gets
started, when the button is clicked.

you may be misunderstanding a bit.
'command proc' statement means to set 'command' option of the button
widget to the procedure.
And the procedure assigned to 'command' option is called when the
button in invoked.
That is, the 'command proc' statement doesn't change the bindings
of the button.
I thought I have to bind a
procedure to a specific event. Does the procedure get bend to a
default event when the "command proc" is used?

If you want to know about bindings on Ruby/Tk,
please read 'bind' and 'bindtags' manual pages of Tcl/Tk,
and examples of binding control of Ruby/Tk (e.g.
'ext/tk/sample/binding_sample.rb' and 'ext/tk/sample/bindtag_sample.rb'
on Ruby's source archive).

Tcl/Tk Ruby/Tk
-------------------------------------------------------------------------
bind target sequence script target.bind(sequence, proc)
bind target sequence +script target.bind_append(sequence, proc)

<modifier-modifier-type-detail> 'modifier-modifier-type-detail'
<<virual_event>> '<virtual_event>'

bindtags target target.bindtags
bindtags target taglist target.bindtags = taglist
 
A

Alexander Fleck

Thanks,
that' s what I needed to know. I just was unsure what this stement does. The TCL/TK site helped a lot.
Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top