Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Tk Button state tied to variable

by choroba (Cardinal)
on Oct 22, 2014 at 22:40 UTC ( [id://1104719]=note: print w/replies, xml ) Need Help??


in reply to Tk Button state tied to variable

Instead of using a tied variable, you can define a subroutine to update the button based on the parameters:
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = 'Tk::MainWindow'->new; my $states = [qw[ disabled normal ]]; my @buttons; for my $i (0, 1) { $buttons[$i] = $mw->Button( -text => "Start $states->[$i]", -state => $states->[$i], -command => sub { warn "B$i" }, )->pack; $mw->Entry( -textvariable => \$states->[$i] )->pack; } $mw->Button( -text => 'Apply', -command => sub { blink($_, $states->[$_]) for 0, 1; } )->pack; sub blink { my ($idx, $state) = @_; $buttons[$idx]->configure( -state => $state ); } MainLoop();

Is it what you wanted?

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-26 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found