Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Binding Perl tk table scrollbars with keyboards up and down arrow keys

by Anonymous Monk
on Dec 17, 2018 at 17:28 UTC ( #1227357=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks, I have table with scrolled option used with table,here I have labels embedded on each table row, By default scrollbar visible area for vertical scrollbar is for 10 rows.
My question is how to adjust the scrollbar visible area as we we move up and down using keyboard up and down keys.
Let's say I have 20 rows, I want to adjust the vertical scrollbar visible area, when I move down from row 10 or move up from current visible area.
Thanks.

  • Comment on Binding Perl tk table scrollbars with keyboards up and down arrow keys

Replies are listed 'Best First'.
Re: Binding Perl tk table scrollbars with keyboards up and down arrow keys
by Discipulus (Abbot) on Dec 17, 2018 at 18:35 UTC
    Hello,

    waiting the wake up of Tk masters, i suppose, in your binding of the down arrow key,you can modify the position of the scrollbar too:  $scrollbar->set(first, last);

    This can used in conjunction of the -yscrollcommand of the table widget in your case.

    See Tk::Scrollbar documentation.

    Posting a short, working code, will help others to contribute

    L*

    UPDATE see also Re: Perl Tk issue with mouse wheel scrolling

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Thanks, i am using scrollbar option in table, I tried to use (scroll, moveto, units) with some row calculations, it is working but not that clean.
      set method looks good need to try that.
      Meanwhile someone could suggest more would be great help with the table -scrollbar option

        Hi, see Need help finding which column/row the mouse cursor is over in Tk.... You might be able to get your current scrollbar position, then use $scrollbar->set(first, last); to adjust your new range. You may even be able to juggle the code in the -scrollcommand option, and use the -fixedrows and or -fixedcolumns options to select your range. Here is something that you could look at to start your mind working.
        #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Table; my $mw= tkinit; #$mw->geometry("400x400+100+100"); my $table = $mw->Scrolled('Table', -rows =>2, -columns => 100, -fixedrows => 2, #trick to hide scrollbars -fixedcolumns => 5, -scrollbars => 'soe', -takefocus => 1,)->pack(-fill=>'both', -expand=>1); my %widgets; for my $row(1..10){ for my $col(1..100){ $widgets{$row}{$col} = $table->Button( -text=> "$row - $col", -background => 'white', -command => sub{ do_me($row,$col) } ); $table->put( $row,$col,$widgets{$row}{$col} ); } } MainLoop; sub do_me{ my ($row, $col) = @_; print "$row $col\n"; }

        I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1227357]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-12-03 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?