Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: PERL Tk label(-textvariable))

by State_Space (Novice)
on Aug 26, 2015 at 18:59 UTC ( [id://1140099]=note: print w/replies, xml ) Need Help??


in reply to Re: PERL Tk label(-textvariable))
in thread PERL Tk label(-textvariable))

use strict; use warnings; use Tk; use POSIX; my $red; my $green; my $blue; my $mw = MainWindow->new; $mw->title('Raw Renamer'); my $right_frame = $mw->Label->pack(-side => 'left', -anchor => 'n', -e +xpand => 1); my $text_frame = $right_frame->Label->pack(-side => 'left', -anchor => + 'n', -expand => 1); $text_frame->Label(-text =>"Red")->pack(-side => 'top', -anchor => 'w' +); $text_frame->Label(-text =>"Green")->pack(-side => 'top', -anchor => ' +w'); $text_frame->Label(-text =>"Blue")->pack(-side => 'top', -anchor => 'w +'); my $variable_frame = $right_frame->Label->pack(-side => 'left', -ancho +r => 'n', -expand => 1); my $red_frame = $variable_frame->Label(-textvariable =>\$red)->pack(-s +ide => 'top'); my $green_frame = $variable_frame->Label(-textvariable =>\$green)->pac +k(-side => 'top'); my $blue_frame = $variable_frame->Label(-textvariable =>\$blue)->pack( +-side => 'top'); Intialize(); MainLoop; sub Intialize { while(1) { $red = floor(5*rand()); $red_frame->update; sleep 1; $green = floor(5*rand()+10); $green_frame->update; sleep 1; $blue = floor(5*rand()+20); $blue_frame->update; sleep 1; } }

Replies are listed 'Best First'.
Re^3: PERL Tk label(-textvariable))
by fishmonger (Chaplain) on Aug 26, 2015 at 19:33 UTC

    How many frames to you believe you created? It's not as many as you think. The answer is 0.

    Try this version.

    #!/usr/bin/perl use strict; use warnings; use Tk; use POSIX; my $red; my $green; my $blue; my $mw = MainWindow->new; $mw->geometry('300x300'); $mw->title('Raw Renamer'); my $right_frame = $mw->Frame->pack(-side => 'left', -anchor => 'n', -expand => 1); my $text_label = $right_frame->Label->pack(-side => 'left', -anchor => 'n', -expand => 1); $text_label->Label(-text =>"Red")->pack(-side => 'top', -anchor => 'w'); $text_label->Label(-text =>"Green")->pack(-side => 'top', -anchor => 'w'); $text_label->Label(-text =>"Blue")->pack(-side => 'top', -anchor => 'w'); my $variable_frame = $mw->Frame->pack(-side => 'left', -anchor => 'n', -expand => 1); my $red_label = $variable_frame->Label(-textvariable =>\$red)->pack(- +side => 'top'); my $green_label = $variable_frame->Label(-textvariable =>\$green)->pac +k(-side => 'top'); my $blue_label = $variable_frame->Label(-textvariable =>\$blue)->pack +(-side => 'top'); Intialize(); MainLoop; sub Intialize { while(1) { $red = floor(5*rand()); $red_label->update; sleep 2; $green = floor(5*rand()+10); $green_label->update; sleep 2; $blue = floor(5*rand()+20); $blue_label->update; sleep 2; } }
      Excellent! I copied some old code for TK formatting and didn't change those labels to frames. Thank you very much!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-19 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found