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

Hello, I would like to jazz-up my app. For that i like to draw some frames around listboxes. This turns out a bit harder than I hoped. When I get a Listbox inside a LabFrame, I cannot set the content of the list anymore :(
Some line of the code (I hope I kept the essential):
use Tk; use Tk::LabFrame; my $listn =$mw->LabFrame(-label=>"New", -labelside=>'acrosstop')->pack; $listn =$mw->Scrolled(qw/Listbox -foreground red -selectforeground blu +e/)->pack; $listn->grid(-row=>0,-column=>0,-columnspan=>2,-sticky=>'nsew'); foreach $key (sort keys %allevents) { $listn->insert('end', $key); }
Can someone help me to get a frame around a listbox in a grid?

Thanks a lot, F.

Update: Thank you for the correction. Now I understand what needs to be done, and made it working. Sorry for my sloppy copying of the original code.

Replies are listed 'Best First'.
Re: Tk::LabFrame and Listbox
by zentara (Cardinal) on Apr 28, 2005 at 11:37 UTC
    Your question and code example make no sense what-so-ever. First you ask how to draw some frames around listboxes. Ok, I showed the code below, and I showed how to add to the listbox.

    Now your code is just a wild *ss guess. First you define $listn to be a LabFrame, then you redefine it to be a Scrolled Listbox, then you try to grid it!! You don't mix grid and pack, you must stick with one or the other. So always post working snippets, and copy&paste them in, so there are no errors.

    If you are trying to put multiple scrolled Listboxes into your Labframe, you can add subframes, or a Table to your fabframe, and put listboxes into them.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::LabFrame; my $mw = tkinit; my $lframe = $mw->LabFrame(-label=>"New", -labelside=>'acrosstop')->pack; my $listn = $lframe->Scrolled(qw/Listbox -foreground red -selectforegr +ound blue/)->pack; my @allevents =( 1..100); foreach my $key (@allevents) { $listn->insert('end', $key); } $mw->Button(-text => "Add to Listbox", -command=> sub{ $listn->insert('end', 'foobar'); $listn->see('end'); })->pack; MainLoop;

    I'm not really a human, but I play one on earth. flash japh