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

Is it possible to execute a callback that is bound to a Tk::Button repeatedly, while the button is pressed?

I tried using the -repeatdelay and -repeatinterval options, but they didn't seem to do any thing.

use warnings; use strict; use Tk; my $num = 0; my $mw = tkinit(); my $button = $mw->Button(-text => $num)->pack(); $button->bind('<Button-1>', \&buttonPressed); $mw->MainLoop(); sub buttonPressed{ #this subroutine should be executed if the button is clicked once, #or repeatedly executed if the button is held down. print "."; $button->configure(-text => $num++); }
  • Comment on Execute Tk::Button every X interval while button is pressed (and not released)
  • Download Code

Replies are listed 'Best First'.
Re: Execute Tk::Button every X interval while button is pressed (and not released)
by bcarroll (Pilgrim) on Feb 13, 2012 at 15:26 UTC

    I figured it out, without having to bind a callback to the button (using the "-command" option)

    use warnings; use strict; use Tk; my $num = 0; my $mw = tkinit(); my $button = $mw->Button( -text => $num, -repeatdelay => 25, -repeatinterval => 25, -command => sub{ buttonPressed(); } )->pack(); $mw->MainLoop(); sub buttonPressed{ #this subroutine will be executed if the button is clicked once, #or repeatedly executed if the button is held down. print "."; $button->configure(-text => $num++); }
      use Tk; sub w{ warn @_ } tkinit->Button( qw/ -repeatdelay 25 -repeatinterval 25 -command /, \&w, )->pack; MainLoop;