From: Hidetoshi NAGAI Date: 2005-10-11T23:02:28+09:00 Subject: Re: Tk, default event bindings From: "Alexander Fleck" Subject: Tk, default event bindings Date: Tue, 11 Oct 2005 18:56:54 +0900 Message-ID: > 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' <> '' bindtags target target.bindtags bindtags target taglist target.bindtags = taglist -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)