Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

TK textvariable not updating

by Stoney2005 (Acolyte)
on May 28, 2011 at 19:14 UTC ( [id://907154]=perlquestion: print w/replies, xml ) Need Help??

Stoney2005 has asked for the wisdom of the Perl Monks concerning the following question:

So I asked this in the chatterbox. tye helped me try and debug it but i'm just not having much luck. with perl tk you can tie a label's text to a variable and when the variable changes it will update the label's text. sounds nice right? well its not working so well for me. 1st try
#!/usr/bin/env perl use Tk; use Time::Stopwatch; $mw = new MainWindow; #Initialize main window $ongoing_time = 0; my $label_running_time_time = $mw -> Label(-textvariable=> \$ongoing_t +ime, -relief=>'groove') -> grid(-row=>9,-column=>2); # bind with tie: +:watch my $button_start_recording = $mw -> Button(-text => "Start", -command +=>\&start_recording_button) -> grid(-row=>10,-column=>1); # duuh my $button_stop_recording = $mw -> Button(-text => "Stop", -command => +\&stop_recording_button) -> grid(-row=>10,-column=>3); # duhh sub start_recording_button {tie $ongoing_time, 'Time::Stopwatch';} sub stop_recording_button {print "Time: $ongoing_time\n";} MainLoop;
I also tried using pack instead of grid, telling $mw-> update(); in the subs, i tried telling $label_running_time_time to update in the subs. I'm kinda at a loss for how to fix it. http://www.ibm.com/developerworks/linux/library/l-ptkwidg/ i used this for reference. specifically the pathentry widget. any help would be appreciative. Also not sure if it will make a difference but i'm running perl v5.10.1 on x86_64-linux-gnu-thread-multi on debian 2.6.38-2-amd64

UPDATE:: It appears that tye was right the variable $ongoing_time is not updated until it's called specifically. crap. anyone have a idea for initiating a timer?

UPDATE:: I found a solution. I'd like it in a straight string tho.
use Tk; use Time::Duration; $start_time = time(); print "Start Time: $start_time\n"; $mw = MainWindow->new(); $timi = $mw->Label( -textvariable=>\$elapsed_time, -foreground=>'blue' + )->pack; $mw->Button( -text=>'Quit', -command=>sub{ exit } )->pack; $mw->Button( -text=>'Update', -command=>sub{ print "New Time: $elapsed +_time\n"; } )->pack; sub update_time {$elapsed_time = concise(duration_exact(time() - $star +t_time)); $timi->update();} $timi->repeat(50,\&update_time); MainLoop;
In a bit if i can find a new one then i'll post it

UPDATE:: I'm happy for the update function. The new code is use Time::Format; sub update_time {$elapsed_time = time_format('mm:ss', (time() - $start_time));$timi->update(); $progress->value((time() - $start_time));}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://907154]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found