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


in reply to Re^2: Tk::Scale, how to avoid callback when displayed?
in thread Tk::Scale, how to avoid callback when displayed?

Hi perltux,

Would it be satisfactory to simply ignore the first call?

Using the example Khen1950fx gave (and fixing the scoping issue with $s) you could do it like this:

#!/usr/bin/perl use strict; use warnings; use Tk; my $top = MainWindow->new(); $top->title("scale tests"); my $f = $top->Frame( -relief => 'ridge', -borderwidth => 3, ); my $s; $s = $top->Scale( "-orient" => "horizontal", "-length" => 300, "-from" => 0, "-to" => 250, "-tickinterval" => 25, "-command" => sub { use feature 'state'; state $ncalls++ or return; printf "Callback: Scale(%d)\n", $_[0]; $f->configure( '-width' => $s->get ) } ); $s->pack(-side => 'left', -fill => 'y'); $f->pack(-side => 'right', -fill => 'y'); Tk::MainLoop;
say  substr+lc crypt(qw $i3 SI$),4,5