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

I'm just trying out Tk::Table and I'm looking for the means of determine in which cell the cursor resides.

Replies are listed 'Best First'.
Re: Cursor position in Tk::Table
by zentara (Cardinal) on Sep 11, 2006 at 20:07 UTC
    There are not too many methods in Tk::Table's perldoc, is there? :-)

    Here is a simple way. But ideally, you would want to find a way to find the widget under the 'current cursor' position, then use the Posn method to get it's row and column. Sometimes, the simplest is the best.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Table; #The key point is that the scroll bars only scroll non-fixed columns. my $mw = MainWindow->new; #$mw->geometry("200x200"); my $x; my $y; my $table = $mw->Table (-rows => 9, -columns => 9, -fixedrows => 9)->pack; foreach my $row (0 .. 8) { foreach my $col (0 .. 8) { my $cell = $table->Entry (-width => 4, -text => "$col, $ +row"); $table->put ($row, $col, $cell); $cell->bind('<ButtonPress-1>' => sub{ $x = $col; $y = $row }); } } my $button = $mw->Button(-text => 'Get Current', -command => sub{ print "$x $y\n"; })->pack(); MainLoop;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Cursor position in Tk::Table
by jdtoronto (Prior) on Sep 11, 2006 at 20:07 UTC
    My understanding is that Tk::Table is purely a 'container' - it needs to be populated with other widgets. The other widgets will probably have a -browsecommand that will allow you to track where the selection is.

    Depending on your actual application, there may be better ways around your problem, but we will need to see something more by way of description. You might also want to study the Tk::TList or Tk::HList widget families.

    jdtoronto