【问题标题】:Perl TK BrowseEntry ComboBox default optionPerl TK BrowseEntry ComboBox 默认选项
【发布时间】:2012-12-21 12:27:07
【问题描述】:

我在内部接手了一个 Perl TK 项目。我想知道您如何为使用 BrowseEntry 库的组合框设置默认值。

这是组合框的构造方式。

$tm->ComboBox(
                  -variable    => \$invoice_per_country,
                  -font        => $main::UserPref->{'ListFont'},
                  -background  => 'white',
                  -relief      => 'groove',
                  -width       => 40,
                  -takefocus   => 1,
                  -listwidth   => 60,
                  -listheight  => scalar @invoice_countries,
                  -forcematch  => '',
                  -options     => [ @invoice_countries ],
                  -buttontakefocus => 0,
                  -disabledforeground => 'black',
                  -disabledbackground => 'white'

                 )
                 ->pack(-side => 'left',
                        -anchor => 'nw');

invoice_countries 包含两个值:('Canada', 'United States')。 我想知道如何在不切换值顺序的情况下将美国设为默认值(我们将添加更多国家/地区)。

【问题讨论】:

  • 它应该反映 $invoice_per_country 中的任何值,只需在打包之前将其设置为“美国”。
  • 感谢查尔斯成功了。就在它上面涂上光泽。由于您将其作为评论留下,因此不确定我如何接受您的回答。

标签: perl combobox perltk


【解决方案1】:

您可以在BrowseEntry 上使用variable 选项:

#!/usr/bin/env perl

use strict;
use warnings;
use Tk;

my @items = ('Canada', 'United States');
my $mw = MainWindow->new;
$mw->geometry('300x300');
my $default = $items[1];

my $be = $mw->BrowseEntry(-label=> 'country', -variable=> \$default,)->place(-y=> 100);
my $lb = $be->Subwidget('slistbox');
$lb->insert('end', @items);

MainLoop();

【讨论】:

    【解决方案2】:

    它应该反映$invoice_per_country 中的任何值,只需在打包之前将其设置为“美国”(或者甚至在之后,PerlTk 将跟随变量)。

    【讨论】:

      【解决方案3】:

      可以使用browserentry的configure方法 $sel->configure(-variable => );

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-17
        • 1970-01-01
        • 2013-05-23
        • 2015-11-14
        • 2018-12-26
        相关资源
        最近更新 更多