Home > Archive > PerlTk > January 2005 > Scale widget executes it's command when mapped
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Scale widget executes it's command when mapped
|
|
| gerhard.petrowitsch@philips.com 2005-01-21, 8:58 am |
| Hi all,
talking about the Scale widget, I remembered another issue.
Unlike other widgets (like Button, Checkbutton, ...), the Scale
widget executes it's -command code, when it's mapped (or
close to that time).
See this little example:
use Tk;
my $mw = MainWindow->new();
$mw->Scale(-from => 0, -to => 10, -length => 300, -width => 10,
-command => sub { print "*" })->pack();
$mw->Button(-text => "Test", -command => sub { print "+" })->pack();
MainLoop;
When you start it, it immediately prints a * to the shell, but
no +. So the Button behaves as expected, the Scale
act 'prematurely'.
That is does so is annoying and doesn't make sense to me.
I always have to build this 'return unless ($first++)' type of
code into the command code of the Scale.
Regards,
Gerhard
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
| |
| Steve Lidie 2005-01-21, 3:58 pm |
|
On Jan 21, 2005, at 2:24 AM, gerhard.petrowitsch@philips.com wrote:
> Hi all,
>
> talking about the Scale widget, I remembered another issue.
> Unlike other widgets (like Button, Checkbutton, ...), the Scale
> widget executes it's -command code, when it's mapped (or
> close to that time).
Yes, that's known .. IIRC a few other widgets do that as well. I think
I (at one time) had a reasonable work-around, but nothing comes to
mind.
> See this little example:
>
> use Tk;
> my $mw = MainWindow->new();
> $mw->Scale(-from => 0, -to => 10, -length => 300, -width => 10,
> -command => sub { print "*" })->pack();
> $mw->Button(-text => "Test", -command => sub { print "+" })->pack();
> MainLoop;
>
> When you start it, it immediately prints a * to the shell, but
> no +. So the Button behaves as expected, the Scale
> act 'prematurely'.
Here's a kluge:
#!/usr/local/bin/perl -w
use Tk;
my $mw = MainWindow->new();
my $s = $mw->Scale(-from => 0, -to => 10, -length => 300, -width =>
10)->pack();
$mw->update; $s->configure( -command => sub { print "*" } );
$mw->Button(-text => "Test", -command => sub { print "+" })->pack();
MainLoop;
>
> That is does so is annoying and doesn't make sense to me.
> I always have to build this 'return unless ($first++)' type of
> code into the command code of the Scale.
With luck an expected snow storm will trap me in front of my computer
this w end and I'll address this and all your previous mails ;)
>
> Regards,
> Gerhard
>
> -++**==--++**==--++**==--++**==--++**==--++**==--++**==
> This message was posted through the Stanford campus mailing list
> server. If you wish to unsubscribe from this mailing list, send the
> message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server. If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@lists.stanford.edu
|
|
|
|
|