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

Dear Monks,
I have a script which will get data from mysql and populate it in to listbox. Data has more than 40 rows and 20 columns. Currently i used "|" delimiter to separate the column. For separating rows i don't know the way. I want to display the data like excel format.

If anyone could point me in the right direction, it would be much appreciated.

  • Comment on Perl Tk : show list box items in grid style

Replies are listed 'Best First'.
Re: Perl Tk : show list box items in grid style
by lamprecht (Friar) on May 19, 2010 at 09:38 UTC
Re: Perl Tk : show list box items in grid style
by biohisham (Priest) on May 19, 2010 at 09:45 UTC
    Since you are using Tk then you have either Tk::GridColumns or Tk::Table, the later is scrollable and provides a nice layout.....


    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

      In Tk::Table and Tk::TableMatrix there is no click event. My Requirement is If i click any row it should affect other list box.

      I tried with Tk::MListbox module. But here height option is not working.

        In Tk::Table and Tk::TableMatrix there is no click event.

        Example of Tk::TableMatrix in "list mode". The user can click a row and the program responds with a message in the console."

        use strict; use warnings; use Tk; use Tk::TableMatrix; my $main = MainWindow->new; $main->title("TM - in list mode"); my $xtvar; foreach my $row (0 .. 7){ foreach my $col (0 .. 2){ if ($col == 0) { $xtvar->{"$row,$col"} = "click row $row"; } else { $xtvar->{"$row,$col"} = "r$row, c$col"; } } } my $xtable = $main->Scrolled( 'TableMatrix', -rows => 8, -cols => 3, -ipadx => 3, -variable => $xtvar, -selectmode => 'single', -selecttype => 'row', -resizeborders => 'none', -state => 'disabled', -cursor => 'top_left_arrow', -bg => 'white', -scrollbars => 'ose', )->pack; # Clean up if mouse leaves the widget $xtable->bind( '<FocusOut>', sub { my $w = shift; $w->selectionClear('all'); } ); # Highlight the cell under the mouse $xtable->bind( '<Motion>', sub { my $w = shift; my $Ev = $w->XEvent; if ( $w->selectionIncludes( '@' . $Ev->x . "," . $Ev->y ) ) { Tk->break; } $w->selectionClear('all'); $w->selectionSet( '@' . $Ev->x . "," . $Ev->y ); Tk->break; } ); # MouseButton 1 event $xtable->bind( '<1>', sub { my $w = shift; $w->focus; my ($rc) = @{ $w->curselection }; # Do something with the selection print " Selection: $rc\n"; } ); MainLoop;