• binding to Button class

    From xol odho@21:1/5 to All on Wed Jul 27 12:06:06 2022
    Hello. Learning some Tk basics here.

    It seems that binding <Enter> to the Button class does not work as I would expect. For instance, this:

    pack [button .b1 -text b1 -command {exit 1}]
    bind Button <Enter> {puts "Button <Enter> : %W"}

    When the mouse cursor enters the button area, it doesn't highlight properly, and does not respond to click so the command is not executed. However, if the event is bound to the specific button widget then it works ok:

    pack [button .b1 -text b1 -command {exit 1}]
    bind .b1 <Enter> {puts ".b1 <Enter>"}

    Now the button reacts properly.

    So why is the behavior different? In both cases it is the same proc that is bound to the same <Enter> event, just the binding tag is different. I find this confusing. What's wrong?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to xol odho on Wed Jul 27 22:17:58 2022
    On 27/07/2022 21:06, xol odho wrote:
    So why is the behavior different? In both cases it is the same proc that is bound to the same <Enter> event, just the binding tag is different. I find this confusing. What's wrong?

    The difference is that by binding to the <Enter> event in the Button
    class, you overwrite the normal class binding that takes care of
    highlighting the button and setting up variables needed when clicking
    the button. That's why those things stop working.

    If you would add your binding instead of replacing the standard binding,
    it works (note the "+"):

    bind Button <Enter> {+puts "Button <Enter> : %W"}


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From xol odho@21:1/5 to All on Wed Jul 27 15:31:35 2022
    I see! Hey, many thanks for the tip, it works now. I had a suspicion that binding <Enter> to the whole Button class was disrupting something. Now it's clear. So one has to be careful with these types of general bindings.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerald Lester@21:1/5 to xol odho on Thu Jul 28 10:21:34 2022
    On 7/27/22 17:31, xol odho wrote:
    I see! Hey, many thanks for the tip, it works now. I had a suspicion that binding <Enter> to the whole Button class was disrupting something. Now it's clear. So one has to be careful with these types of general bindings.

    Generally it is a good idea to look at what bindings exist on a class
    before doing a binding to it.

    bind <Button>

    will return all the events currently bound to the Button class.


    --
    +----------------------------------------------------------------------+
    | Gerald W. Lester, President, KNG Consulting LLC |
    | Email: [email protected] | +----------------------------------------------------------------------+

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Thu Jul 28 18:23:04 2022
    Am 28.07.22 um 17:21 schrieb Gerald Lester:
    On 7/27/22 17:31, xol odho wrote:
    I see! Hey, many thanks for the tip, it works now. I had a suspicion
    that binding <Enter> to the whole Button class was disrupting
    something. Now it's clear. So one has to be careful with these types
    of general bindings.

    Generally it is a good idea to look at what bindings exist on a class
    before doing a binding to it.

    bind <Button>

    will return all the events currently bound to the Button class.



    You meant surely

    bind Button

    rather than

    bind <Button>

    --
    Csaba Nemethi https://www.nemethi.de mailto:[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gerald Lester@21:1/5 to nemethi on Fri Jul 29 08:11:57 2022
    On 7/28/22 11:23, nemethi wrote:
    Am 28.07.22 um 17:21 schrieb Gerald Lester:
    On 7/27/22 17:31, xol odho wrote:
    I see! Hey, many thanks for the tip, it works now. I had a suspicion
    that binding <Enter> to the whole Button class was disrupting
    something. Now it's clear. So one has to be careful with these types
    of general bindings.

    Generally it is a good idea to look at what bindings exist on a class
    before doing a binding to it.

    bind <Button>

    will return all the events currently bound to the Button class.



    You meant surely

        bind Button

    rather than

        bind <Button>

    Yeap

    --
    +----------------------------------------------------------------------+
    | Gerald W. Lester, President, KNG Consulting LLC |
    | Email: [email protected] | +----------------------------------------------------------------------+

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)