Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Setting value in Tk -textvariable

by Necos (Friar)
on Aug 07, 2002 at 01:49 UTC ( [id://188212]=note: print w/replies, xml ) Need Help??


in reply to Setting value in Tk -textvariable

Let's take Chmrr's example one step further... Here's a snippet of code that I use in one of my programs:
sub _usr_next { $window_hash->{main}{children}{label}->configure(-textvariable, $w +indow_hash->{main}{children}{text}); }
The configure method will set the parameter (in this case, -textvariable), to a new value. You can also use the get method to retrieve the value. So, let's say you need to update a label. You could make a button that calls the sample code as a callback. In total, it would look something like this. WARNING: UNTESTED!!!

#/usr/bin/perl -w use strict; use Tk; my $window_hash = {}; $window_hash->{main}->{main} = new MainWindow(); $window_hash->{main}->{children} = {}; $window_hash->{main}->{children}->{frame} = $window_hash->{main}{main} +->Frame()->grid(-column, 0, -row, 0, -sticky, 'news'); $window_hash->{main}->{globals}->{test1} = "hi"; $window_hash->{main}->{globals}->{test2} = "there"; $window_hash->{left_label} = $window_hash->{main}->{children}->{frame} +->Label(-textvariable, $window_hash->{main}->{globals}->{test1})->pac +k(-side, 'left'); $window_hash->{right_label} = $window_hash->{main}->{children}->{frame +}->Label(-textvariable, $window_hash->{main}->{globals}->{test2})->pa +ck(-side, 'right'); $window_hash->{test_button} = $window_hash->{main}->{children}->{frame +}->Button(-command, \&_usr_next())->pack(-side, 'bottom'); MainLoop; sub _usr_next { $window_hash->{left_label}->configure(-textvariable, $window_hash- +>{main}->{globals}->{test2}); $window_hash->{right_label}->configure(-textvariable, $window_hash +->{main}->{globals}->{test1}); }
The above method of using hash of hash of hashes method of Tk objects was suggested to me by NULE. It's actually a very creative method of making windows in Tk. The garbage collector apparently uses a linked list to store the parent and child windows, so you can put them anywhere and they will be properly garbage collected. I hope the example code is some help...

Theodore Charles III
Network Administrator
Los Angeles Senior High
4650 W. Olympic Blvd.
Los Angeles, CA 90019
323-937-3210 ext. 224
email->secon_kun@hotmail.com
perl -e "map{print++$_}split//,Mdbnr;"

Log In?
Username:
Password:

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

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

    No recent polls found