Sunday, January 2, 2011

TKx: Scroll frame

use Tkx;
Tkx::package_require("tile");
Tkx::package_require("BWidget");

my $mw = Tkx::widget->new(".");
my $sw = $mw->new_ScrolledWindow(-managed => 0);
my $sf = $sw->new_ScrollableFrame();

Tkx::grid(rowconfigure => $mw, 0, -weight => 1);
Tkx::grid(columnconfigure => $mw, 0, -weight => 1);

# This is the one tricky conversion.  We are getting a widget ref
# back from Tcl that has never been seen as a widget in Tkx, thus
# the Tkx::widget call makes the right kind of object.
my $subf = Tkx::widget->new($sf->getframe());

my $b;
for my $row (1..20)
{
    for my $col (1..20)
    {
        $b = $subf->new_ttk__button(-text => "$row,$col",
                        -command => sub { exit(); });
        $b->g_grid(-row => $row, -column => $col);
    }
}

$sw->setwidget($sf);
$sw->g_grid(-row => 0, -column => 0, -sticky => "nsew");

foreach (Tkx::SplitList($mw->g_winfo_children))
{
    Tkx::grid_configure($_, -padx => 2, -pady => 2);

}

Tkx::update('idletasks');
#Tkx::wm_geometry($mw,
#    Tkx::winfo_reqwidth($subf) . "x" . Tkx::winfo_reqheight($subf));
Tkx::wm_geometry($mw, (Tkx::winfo('reqwidth', $subf) + 10) . "x" .
    (Tkx::winfo('reqheight', $subf) + 10));

Tkx::MainLoop;

No comments: