Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Keyboard traversal for Tk::Notebook

by Anonymous Monk
on Sep 12, 2003 at 15:26 UTC ( [id://291100]=perlquestion: print w/replies, xml ) Need Help??

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

Does anyone know how to bind keys to a specific tab in a Tk::Notebook. I know you have to use the "underline" option to specify the index of a charcter in the label, but I'm lost in trying to bind a specific keystroke to the specified charcter in order to bring that tab into focus.

Any ideas?

Replies are listed 'Best First'.
Re: Keyboard traversal for Tk::Notebook
by converter (Priest) on Sep 12, 2003 at 19:18 UTC

    I've tested a simple two-page NoteBook here and have no problems with the key bindings on my Linux box, so either there's a problem with Tk::NoteBook on your platform, or you're doing something wrong in your code.

    It would be very helpful if you would post a small snippet of code that illustrated the problem so that other monks could run the same test on their machines and compare their results with yours.

    converter

      This code is straight from the widget demo, and I'm still unable to select a tab using ALT or CTRL
      # Notebook, selectable pages. use Tk; use Tk::DialogBox; use Tk::NoteBook; use Tk::LabEntry; my $name = "Rajappa Iyer"; my $email = "rsi\@netcom.com"; my $os = "Linux"; use vars qw($top); $top = MainWindow->new; my $pb = $top->Button(-text => "Notebook", -command => \&donotebook); $pb->pack; MainLoop; my $f; sub donotebook { if (not defined $f) { # The current example uses a DialogBox, but you could just # as easily not use one... replace the following by # $n = $top->NoteBook(-ipadx => 6, -ipady => 6); # Of course, then you'd have to take care of the OK and Cancel # buttons yourself. :-) $f = $top->DialogBox(-title => "Personal Profile", -buttons => ["OK", "Cancel"]); my $n = $f->add('NoteBook', -ipadx => 6, -ipady => 6); my $address_p = $n->add("address", -label => "Address", -underline + => 0); my $pref_p = $n->add("pref", -label => "Preferences", -underline = +> 0); $address_p->LabEntry(-label => "Name: ", -labelPack => [-side => "left", -anchor => "w"], -width => 20, -textvariable => \$name)->pack(-side => "top", -anchor => "nw +"); $address_p->LabEntry(-label => "Email Address:", -labelPack => [-side => "left", -anchor => "w"], -width => 50, -textvariable => \$email)->pack(-side => "top", -anchor => "n +w"); $pref_p->LabEntry(-label => "Operating System:", -labelPack => [-side => "left"], -width => 15, -textvariable => \$os)->pack(-side => "top", -anchor => "nw") +; $n->pack(-expand => "yes", -fill => "both", -padx => 5, -pady => 5, -side => "top"); } my $result = $f->Show; if ($result =~ /OK/) { print "name = $name, email = $email, os = $os\n"; } }
      Any help is greatly appreciated
Re: Keyboard traversal for Tk::Notebook
by jdtoronto (Prior) on Sep 12, 2003 at 15:42 UTC
    From the ActiveState documentation for Notebook.

    "The NoteBook widget provides a notebook metaphor to display several windows in limited space. The notebook is divided into a stack of pages of which only one is displayed at any time. The other pages can be selected by means of choosing the visual ``tabs'' at the top of the widget. Additionally, the <Tab> key may be used to traverse the pages. If -underlineis used, Alt- bindings will also work."

    Highlighting is mone.

    jdtoronto

      I'm using the underline option ...
      ... my $foo =$tab->add("FOO", -label => "Testing Tab", -underline => '0'); ...
      But Alt-T doesn't bring the tab into focus with multiple tabs
        No it doesn't does it!

        I realised after I wrote that note that I wasn't using the bindings on the Notebook widget, and when I tried it, like you I found it doesn't work.

        I won't be able to get back to it for a few hours, but have a look at Tk::bind in your doc tree, that might give the answer.

        The section in the Tk::Notebook doc's is taken stright from the Tcl docs unchanged - and obviously does not apply!

        jdtoronto Updated:

        Check also the docs for Tk::autobind. It seems relevant, but I haven't had time to try coding anything yet. Good luck.

        john

        I haven't used Tk in several years, so I'm pulling this out of thin air, but...might passing a true value for -underline help?
        I'm not familiar with Tk::Notebook and so the following may be way off:

        I believe you need to run 'bind' outside of the definition of your button. Using the 'underline' option literally only buys you the underlining of the '0'th position ('T') of the label. To actually make it DO something when you press <Alt-Key-T>, wouldn't you do something like the following in a statement outside of the 'my $foo' statement? ($tl is the toplevel widget where your widget lives)

        $tl->bind("<Alt-Key-T>", sub { $foo->invoke(); } );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found