【问题标题】:Perl Tkx menu "-underline" doesn't seem to work properlyPerl Tkx 菜单“-underline”似乎无法正常工作
【发布时间】:2015-02-16 11:26:12
【问题描述】:

我一直在关注Tkx::Tutorial,尝试学习如何使用 Perl 制作 GUI。我到了它有一个如何创建菜单并遵循它的示例的部分。除了一项功能外,它几乎完全正确。 -underline 部分似乎无法正常工作。

-underline => 0 应该在菜单文本的第一个字符下划线,并允许您将第一个字母用作键盘快捷键,而不必单击它。

代码如下:

#!/usr/bin/perl

use strict;
use warnings;
use Tkx;

our $VERSION = '1.00';

(my $progname = $0) =~ s,.*[\\/],,;
my $IS_AQUA = Tkx::tk_windowingsystem() eq "aqua";

Tkx::package_require('style');
Tkx::style__use('as', -priority => 70);

my $mw = Tkx::widget->new('.');
$mw->configure(-menu => mk_menu($mw));

Tkx::MainLoop();
exit;

sub mk_menu {
    my $mw = shift;
    my $menu = $mw->new_menu;

    my $file = $menu->new_menu(
        -tearoff => 0,
    );
    $menu->add_cascade(
        -label     => 'File',
        -underline => 0,
        -menu      => $file,
    );
    $file->add_command(
        -label       => 'New',
        -underline   => 0,
        -accelerator => 'Ctrl+N',
        -command     => \&new,
    );
    $mw->g_bind('<Control-n>', \&new);
    $file->add_command(
        -label     => 'Exit',
        -underline => 0,
        -command   => [\&Tkx::destroy, $mw],
    ) unless $IS_AQUA;

    my $help = $menu->new_menu(
        -name    => 'help',
        -tearoff => 0,
    );
    $menu->add_cascade(
        -label     => 'Help',
        -underline => 0,
        -menu      => $help,
    );
    $help->add_command(
        -label   => "\u$progname Manual",
        -command => \&show_manual,
    );

    my $about_menu = $help;
    if ($IS_AQUA) {
        # On Mac OS we want about box to appear in the application
        # menu.  Anything added to a menu with the name "apple" will
        # appear in this menu.
        $about_menu = $menu->new_menu(
            -name => 'apple',
        );
        $menu->add_cascade(
            -menu => $about_menu,
        );
    }
    $about_menu->add_command(
        -label   => "About \u$progname",
        -command => \&about,
    );

    return $menu;
}


sub about {
    Tkx::tk___messageBox(
        -parent  => $mw,
        -title   => "About \u$progname",
        -type    => 'ok',
        -icon    => 'info',
        -message => "$progname v$VERSION\n" .
                    "Copyright 2005 ActiveState. " .
                    "All rights reserved.",
    );
}

此代码将创建以下窗口:

使用“F”作为键盘快捷键无法打开文件菜单,使用“H”无法打开帮助菜单

(注意“New”函数目前什么都不做,所以对它的调用被破坏了。现在应该是这样,所以忽略它。)

单击“文件”菜单后,将打开第二个菜单。在这里,键盘快捷键似乎可以工作,“N”和“E”将执行相应的命令,但它们仍然没有正确加下划线。

为什么这不按他们应该的方式工作?

【问题讨论】:

  • 适用于我在 Windows 7 x64 下的 Perl 5.16.1 和 Tkx 1.09。
  • 如果你在 Windows 上,你需要按 ALT 来获得键盘快捷键。
  • 感谢@gangabass,按 ALT 使其正常工作。

标签: perl user-interface menu underline tkx


【解决方案1】:

按住 ALT 解决了这个问题。

谢谢@gangabas!

【讨论】:

    猜你喜欢
    • 2015-12-07
    • 2017-09-04
    • 2012-05-06
    • 2013-02-17
    • 2017-10-09
    • 2017-08-03
    • 2014-05-02
    • 2011-09-11
    • 2016-02-11
    相关资源
    最近更新 更多