http://www.perlmonks.org?node_id=203642

Stevo_ie has asked for the wisdom of the Perl Monks concerning the following question:

I need to read all the messages that are sent to a perl/tk window eg. mouse_moved, minimise_button_pressed, window_moved, window_resized.
Does anyone know how to retrieve these messages?
Thanx in advance,
StevoIE

Replies are listed 'Best First'.
Re: Reading Tk Window messages
by rir (Vicar) on Oct 08, 2002 at 18:18 UTC
    I suspect you need to hack Tk, use some debugging artifact
    or find another definition of your problem.

    Do to the diverse nature of Tk widgets, there is not
    going to be one SUPER class to alter.

    User level coding of Tk seems to only offer:

    $widget-bind( Tk::Button, "<Button-1>", sub{&handle_event});

    which will alter the specified binding for all
    instances of Tk::Button.

Re: Reading Tk Window messages
by PodMaster (Abbot) on Oct 09, 2002 at 12:28 UTC
    I suspect you're after Tk::bind and/or Tk::bindtags.

    see http://perltk.org for tons of information

    update: see what rir said (hmm, i missed it?)

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Reading Tk Window messages
by ichimunki (Priest) on Oct 09, 2002 at 15:01 UTC
    Take a look at Tk::Toplevel, Tk::Wm, and Tk::after. You can set up a callback that runs periodically in your program to check for some of these things, using $toplevel->geometry() and $toplevel->status()-- this way you can detect when the geometry has changed, or if the user has minimzed or iconfied the application. You can't, unfortunately, directly catch these events as they happen. For that you might want to explore other GUI toolkits that explicitly offer these events as signals.

    One question that I would ask is: why? Tk should handle most of your redrawing needs, and I'm not sure it's interesting to know if the user has tried to minimize the window... unless you're trying to coerce certain behavior.