Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by perltux (Scribe)
on Dec 25, 2012 at 11:34 UTC ( #1010262=note: print w/ replies, xml ) Need Help??


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

I don't quite understand the example code and how it relates to my problem. I tried running it but even your example invokes the command when the scale is first displayed before any user interaction (which is what I would like to avoid).


Comment on Re^2: Tk::Scale, how to avoid callback when displayed?
Re^3: Tk::Scale, how to avoid callback when displayed?
by golux (Pilgrim) on Dec 25, 2012 at 18:59 UTC
    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
      Thanks that could be a viable workaround, I will look into it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010262]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-07-04 20:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls