Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Tk Button state tied to variable

by glenn (Scribe)
on Oct 23, 2014 at 03:39 UTC ( #1104731=note: print w/replies, xml ) Need Help??


in reply to Tk Button state tied to variable

Thanks for telling me about trace. I will give that a try and update with results and working example.

Works, here is what I did for the next person who needs to know.

use Tk; use Tk::Trace; use Tk::Text; my $system = {}; @{$system->{gui}->[0]->{cut_ctl_1}} = ("start", "normal"); @{$system->{gui}->[0]->{cut_ctl_2}} = ("remove", "normal"); $system->{gui}->[0]->{progress}->[0] = "Not running"; my $mainwindow = MainWindow->new(); my $but_ctl_1 = $mainwindow->Button(-textvariable=>\$system->{gui}->[0 +]->{but_ctl_1}->[0], -state=>$system->{gui}->[0]->{but_ctl_1}->[1])-> +grid(-row=>0, -column=>0, -sticky=>"nsew"); my $but_ctl_2 = $mainwindow->Button(%{-textvariable=>\$system->{gui}-> +[0]->{but_ctl_2}->[0], -state=>$system->{gui}->[0]->{but_ctl_2}->[1]) +->grid(-row=>1, -column=>0, -sticky=>"nsew"); my $progress = $mainwindow->Scrolled('Text', -scrollbars=>'osoe', -hei +ght=>5, -width=>30)->grid(-row=>2, -column=>0, -sticky=>"nsew"); $progress->Subwidget('scrolled')->insert( 'end', "$system->{gui}->[0]- +>{progress}->[0]" ); #traces: $frame->traceVariable( \$system->{gui}->[0]->{progress}->[0], 'w', [ \ +&text_update, $progress->Subwidget('scrolled')] ); $frame->traceVariable( \$system->{gui}->[0]->{but_ctl_1}->[1], 'w', [ +\&state_update, $but_ctl_1] ); $frame->traceVariable( \$system->{gui}->[0]->{but_ctl_2}->[1], 'w', [ +\&state_update, $but_ctl_2] ); $mainwindow->after(5000, sub{ $system->{gui}->[0]->{progress}->[0] = "RUNNING"; $system->{gui}->[0]->{but_ctl_1}->[1] = "disabled"; }); MainLoop(); sub text_update { my ($index, $value, $op, $t) = @_; return unless $value; $t->delete("1.0", "end"); $t->insert( 'end', "$value" ); return $value; } sub state_update { my ($index, $value, $op, $b) = @_; return unless $value; $b->configure(-state=>$value); return $value; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2022-01-21 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?