
PapaGeek
User
Mar 22, 2014, 10:48 AM
Post #1 of 11
(12932 views)
|
Tk - Changing the dimensions for a table.
|
Can't Post
|
|
I found some code on line that allows me to create a Tk table in a frame and make it scrollable. The code I am writing can create a number of user definable different tables of various sizes. I basically want the user to be about to select what table they wish to see and have that table appear in the frame/table with the column headers and the first two columns fixed and the rest scrollable. One option might be to create the table way larger than I need and just blank out the extra rows and columns as I update the table content for each request, but it would be nice if the scroll bars showed the bottom of the table when pulled to the bottom, etc. How do I write the second and third lines of the pseudo code at the bottom of this example? When I run the program with the two lines before the pseudo code un-commented, I get the following error:
Tk::Error: Can't modify non-lvalue subroutine call at …tKTable.pl line 53. What is the proper syntax for what I want to do?
#!/usr/bin/perl -w use Tk; use Tk::Table; use strict; my $mw = MainWindow->new; $mw->geometry("475x225"); #$mw->resizable(0,0); $mw->title("Table Example"); $mw->Label( -text=>"Select what report to display" )->pack(); $mw->Button( -text=>"show table 1", -command =>[\&displayTable, 1 ])->pack(); $mw->Button( -text=>"show table 2", -command =>[\&displayTable, 2 ])->pack(); my $table_frame = $mw->Frame()->pack(); my $table = $table_frame->Table(-columns => 18, -rows => 19, -fixedrows => 1, -fixedcolumns => 1, -scrollbars => 'se', -relief => 'raised'); foreach my $col (1 .. 18) { my $tmp_label = $table->Label(-text => "COL " . $col, -width => 8, -relief =>'raised'); $table->put(0, $col, $tmp_label); } foreach my $row (1 .. 18) { foreach my $col (1 .. 18) { my $tmp_label = $table->Label(-text => $row . "," . $col, -padx => 2, -anchor => 'w', -background => 'white', -relief => "groove"); $table->put($row, $col, $tmp_label); } } $table->pack(); my $button_frame = $mw->Frame( -borderwidth => 4 )->pack(); $button_frame->Button(-text => "Exit", -command => sub {exit})->pack(); MainLoop; sub displayTable { my ($tableID) = @_; print "displaying table $tableID\n"; #my $rows = 25; #$table->rows = $rows; =speudoCode my (@tableData,$rows,$columns) = getTableData($tableID); $table->columns = $columns; $table->rows = $rows + 1; # create extra row for headers foreach row for each column my $tmp_label = $table->Label(-text => "get data from my table ($row, $col)", -padx => 2, -anchor => 'w', -background => 'white', -relief => "groove"); $table->put($row, $col, $tmp_label); =cut }
|