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

Hello O’holly Ones

This is also very simple; I have a 3 column table which I would like to display it in this Perl/Tk based form (please see the code below), I have created a frame for this table and also labelled it, However I am not sure on how to create/Insert and populate this table with my values. I have read the Tk.Html and under the heading Tk::Table I found an example which I played around with it trying to understand it, but I still couldn’t grasp the idea. Can someone, “Big Please”, show me how its done.

As always, your divine advice/pointer, or even better, an example is highly appreciated.

BlackAdder
require 5.006; use strict; use Tk 800.005; use Tk::TList; use Tk::Frame; use Tk::DirTree; use Tk::Scrollbar; use Tk::Adjuster; use Tk::DragDrop; use Tk::DropSite; use Tk::Table; use warnings 'all'; use Win32::NetResource; use vars qw/%tk %dr/; $dr{PATH}='c:/'; $dr{server} = ShowServer($dr{PATH}); $dr{perms} = "Permissions: " . $dr{PATH}; $tk{mw} = MainWindow->new (-background=>'white'); $tk{mw}->geometry('700x500'); $tk{top_frame} = $tk{mw}->Frame; $tk{left_frame} = $tk{mw}->Frame; $tk{adjuster} = $tk{mw}-> Adjuster(-widget=>$tk{left_frame},-side=>'le +ft'); $tk{right_frame}=$tk{mw}->Frame; # This frame is where I would like to + have a table. $tk{entry_box}=$tk{top_frame}->Entry(-textvariable=>\ $dr{PATH}); $tk{entry_box_lable}=$tk{top_frame}->Label(-text=>"Path: "); $tk{dir_tree}= $tk{left_frame}->Scrolled('DirTree', -height=>'0', -wid +th=>'0',-scrollbars=>'e',); $tk{dir_tree_label}=$tk{left_frame}->Label(-textvariable=>\ $dr{server +}); $tk{ACL_list}=$tk{right_frame}->Scrolled('TList', -height=>'1', -width=>'1', -scrollbars=>'osoe',); # This list should contain my table $tk{ACL_list_label}=$tk{right_frame}->Label(-textvariable=>\ $dr{perms +}); $tk{entry_box}->bind('<Key-Return>', sub {OnNewPath();}); $tk{top_frame}->pack(qw/-side top -fill x/); $tk{left_frame}->pack(qw/-side left -fill y/); $tk{adjuster}->pack(qw/-side left -fill y/); $tk{right_frame}->pack(qw/-side right -fill both -expand 1/); $tk{entry_box_lable}->pack(qw/-side left -fill both/); $tk{entry_box}->pack(qw/-side top -fill both -expand 1/); $tk{dir_tree_label}->pack(qw/-side top -fill both/); $tk{dir_tree}->pack(qw/-side left -fill both -expand 1/); $tk{ACL_list_label}->pack(qw/-side top -fill both/); $tk{ACL_list}->pack(qw/-side top -fill both -expand 1/); MainLoop; exit(0); sub OnNewPath{ $tk{dir_tree}->delete('all'); $tk{dir_tree}->chdir( $dr{PATH} ); ShowServer($dr{PATH});} sub ShowServer{ my $drive = @_; my $srv; if (Win32::NetResource::GetUNCName(my $unc, $dr{PATH})){ $unc =~ s/^\\\\(\w)+//; $srv = $&; return $dr{server} = "[ Remote Server Name : " . uc($srv) . " +]";} else{ $srv = Win32::NodeName(); return $dr{server} = "[ Local Server Name : " . uc($srv) . " ] +"; }} sub FillTable # or something { #this procedure should populate my table with values which are basical +ly #permission related }

Replies are listed 'Best First'.
Re: Tables in Perl/Tk.
by hiseldl (Priest) on Aug 02, 2002 at 16:39 UTC
    Adding to a table is pretty straight forward. Add the table to your code:
    $tk{right_frame}=$tk{mw}->Frame; # This frame is where I would like to + have a table. $tk{table}=$tk{right_frame}->Table(-rows => 4, -columns => 4, -scrollbars => 'se', );
    ...then add it to your geometry manager, pack:
    $tk{right_frame}->pack(qw/-side right -fill both -expand 1/); $tk{entry_box_lable}->pack(qw/-side left -fill both/); $tk{entry_box}->pack(qw/-side top -fill both -expand 1/); $tk{table}->pack(qw/-side top -fill both -expand 1/);
    I added this sub to insert items into the table:
    sub AddItemToTable { my ($row, $col, $item) = @_; $tk{table}->put($row, $col, $item); }
    Then to test it, I put a call in your OnNewPath sub, e.g.
    $tk{dir_tree}->chdir( $dr{PATH} ); &AddItemToTable($tk{table}->{row}++,$tk{table}->{col}++,$dr{PATH});
    this basically adds an item down the diagonal.

    --
    hiseldl