2014-03-19 30 views
1

我编写简单的Perl/Tk应用程序,我需要将二维数组看作一个网格,例如Delphi的StringGrid。但是我找不到类似于StringGrid的Tk部件。有没有类似的部件?Perl/Tk的StringGrid模拟

+0

是的,这不是我所需要的。 – michaeluskov

回答

2

是的,有一个类似StringGrid的部分。有2个模块可以用于此目的。 Number 1Number 2。我认为Nr1是你正在寻找的。

下面是一个简单的使用的一个简单的例子:

use strict; 
use warnings; 
use Tk; 
use Tk::TableMatrix::Spreadsheet; 
my $mw = Tk::MainWindow->new(-width => 380, -height => 400,); 
$mw->packPropagate(0); 
my %table =(); 
my $t = $mw->Scrolled(
    'Spreadsheet', 
    -cols => 4, 
    -rows => 500, 
    -width => 4, 
    -titlerows => 1, 
    -titlecols => 0, 
    -variable => \%table, 
    -selectmode => 'extended', 
    -titlerows => 1, 
    -titlecols => 1, 
    -bg => 'white', 
    -bg    => 'white', 
    -scrollbars => 'se', 
); 
my $l = $t->Label(-text => 'text',); 
$t->set('1,2', "Name"); 
for(my $c = 0; $c < 500; $c++) { 
    $t->set("$c,0", $c); 
    $t->set("$c,1", $c*100); 
    $t->set("$c,2", $c^17); 
    $t->set("$c,3", $c/5); 
} 
$t->pack(-fill => 'both', -expand => 1); 
$mw->MainLoop(); 
+0

我可以阻止并允许更改单元格的值吗?我可以更改列数和行数吗?我在文档中找不到它,它很差。据我所知,并不是我所知道的 – michaeluskov

+0

。 – 2014-03-20 08:09:16