Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Tk GUI Building with Loops

by Tanalis (Curate)
on Nov 26, 2002 at 11:48 UTC ( [id://215823]=perlquestion: print w/replies, xml ) Need Help??

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

Monks,

I'm currently updating a GUI I wrote some time ago, mainly to allow it to display data in a slightly different way.

I've written a loop to build a repetative part of the GUI, but I'm having problems with data not being placed into the two LabEntry widgets when they changes (it's part of a front end for a database search).

The %objects hash is in scope, and data is being assigned to this correctly. The checkbutton updates correctly when data is returned from the search, it is simply the two LabEntry widgets that don't.

My code for the loop is as follows:

my $dataFrame = $cpWindow -> Frame; foreach my $item ("Data1", "Data2") { my $lc_item = lc($item); $dataFrame -> Label(-text => ' ')->pack(-side => "left"); my $frame = $dataFrame -> Frame(-relief => "groove", -borderwidth => 1); $frame -> Label (-text => "[ $item ]" )->pack; $frame -> Label (-text => " ")->pack; $frame -> LabEntry (-label => "Component:", -width => 5, -labelPack => [ qw/-side left/ ], -textVariable => \$objects{"$lc_item\_component +"} )->pack; my $rat = $frame -> LabEntry(-label => "*Category:", -width => 5, -labelPack => [ qw/-side left/ ], -textVariable => \$objects{"$lc_item\_ +category"}, -state => "disabled" )->pack; $frame -> Checkbutton(-text => "Available", -variable => \$objects{"$lc_item\_a +vailable"}, -onvalue => "Y", -offvalue => "N", -highlightthickness => 0 )->pack; $objects{"$lc_item\_available"} = "N"; $frame -> pack(-side => "left"); }

If anyone can shed any light on this it'd be much appreciated.

Many thanks ..
--Foxcub

Replies are listed 'Best First'.
Re: Tk GUI Building with Loops
by Chmrr (Vicar) on Nov 26, 2002 at 14:48 UTC

    The only problem that I see is that it should be -textvariable, not -textVariable (case matters..). In fact, you should be getting a big fat error with the code as it currently is, complaining about "bad option '-textVariable'".

    Given that change, the following simulation of your code works for me:

    #!/usr/bin/perl -w use Tk; use Tk::LabEntry; $a{bar} = "foo"; $mw = MainWindow->new(); for (1..3) { $mw->LabEntry(-label => "Component:", -width => 5, -labelPack => [ qw/-side left/ ], -textvariable => \$a{bar})->pack; } $mw->after(1000,sub{$a{bar} = "Moose!"}); MainLoop;

    Tangential update: A quarter of a thousand writeups, and counting. I think I need to start attending my local PM-ers anonymous support group.

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-03-28 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found