in reply to Setting value in Tk -textvariable
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!!!sub _usr_next { $window_hash->{main}{children}{label}->configure(-textvariable, $w +indow_hash->{main}{children}{text}); }
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...#/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}); }
|
|---|