in reply to Display new widgets after MainLoop

Try HList, just put the code below to open in a new toplevel, or frame. Also check out a wacky widget I made at Tk-CanvasDirTree, which is a dynamic tree on a canvas. In the below example, you would put the HLists into a Scrolled::Pane, but this simple example just dumps them adjacent to the last in a simple Frame.
#!/usr/bin/perl use strict; use Tk; use Tk::HList; my $mw = MainWindow->new(); $mw->geometry("500x500+100+100"); my $h; #create some sample data my %data; foreach (0..100) { $data{$_}{'name'} = 'name'.$_; $data{$_}{'id'} = rand(time); } #get random list of keys my @keys = keys %data; ################# my $button0 = $mw->Button(-text => 'show list', -command => sub{ showlist() } )->pack; my $button = $mw->Button(-text => 'exit', -command => sub{exit})->pack; my $sortid = $mw->Button(-text => 'Sort by Id', -command => [\&sort_me,1] )->pack; MainLoop; ######################################################### sub showlist{ $h = $mw->Scrolled( 'HList', -header => 1, -columns => 2, -width => 30, -height => 60, -takefocus => 1, -background => 'steelblue', -foreground =>'snow', -selectmode => 'single', -selectforeground => 'pink', -selectbackground => 'black', # -browsecmd => \&browseThis, )->pack(-side => "left", -anchor => "n"); my $nameh = $h->header('create', 0, -text => ' Name ', -borderwidth => 3, -headerbackground => 'steelblue', -relief => 'raised'); my $idh = $h->header('create', 1, -text => ' ID ', -borderwidth => 3, -headerbackground => 'lightsteelblue', -relief => 'raised'); foreach (@keys) { my $e = $h->addchild(""); #will add at end $h->itemCreate ($e, 0, -itemtype => 'text', -text => $data{$_}{'name'}, ); $h->itemCreate($e, 1, -itemtype => 'text', -text => $data{$_}{'id'}, ); } } sub sort_me{ my $col = shift; my @entries = $h->info('children'); my @to_be_sorted =(); foreach my $entry(@entries){ push @to_be_sorted, [ $h->itemCget($entry,0,'text'), $h->itemCget($entry,1,'text') ]; } my @sorted = sort{ $a->[$col] cmp $b->[$col] } @to_be_sorted; my $entry = 0; foreach my $aref (@sorted){ # print $aref->[0],' ',$aref->[1],"\n"; $h->itemConfigure( $entry, 0, 'text' => $aref->[0] ); $h->itemConfigure( $entry, 1, 'text' => $aref->[1] ); $entry++; } $mw->update; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Replies are listed 'Best First'.
Re^2: Display new widgets after MainLoop
by swe9 (Initiate) on Aug 11, 2010 at 18:16 UTC
    I looked at HList but it wasn't clear that I could easily create a scrolling grid of thumbnails with it. I want a rectangular area with rows and columns of thumbnails that I can select and operate on. (Ultimately I'd like to be able to remove thumbnails as operations are completed but that's for later.)
      You can use Hlist for thumbnails, see ztkdb and ztkdb-sql

      HList is the most configurable list in Tk.

      You can also use Gtk2's various list widgets, which accept pixbuf fields.


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku

        The page you provided had dead links, but I found it at http://www.perlmonks.org/index.pl?displaytype=print;node_id=338291. It's dying with

        Can't call method "get" on an undefined value at ztkdb14a.pl line 1715.

        when I run it in the command window (on Windows 7.)

        I'll start looking at it to see if I can learn what it has to teach me. Thanks!!!

        Update: I got the window to open after moving the directory where admin privileges weren't required and creating admin.jpg and default.jpg in the thumbs directory. The HList looks like a one dimensional list but maybe it'll be clear how to extend it to multiple columns...