- 论坛徽章:
- 0
|
本帖最后由 simon_stone 于 2016-09-18 13:40 编辑
- <p>&listBox(-title=>'abc',-selectmode=>'multiple',-list=>['a','b','c']);</p><p>sub listBox {
- my %hash = @_;
- $hash{-height} = 10 unless defined $hash{-height};
- $hash{-width} = 5 unless defined $hash{-width};
- my $mw = MainWindow->new;
- my $dialog = $mw->DialogBox(-title => $hash{-title},
- -buttons => ["OK","Cancel"]);
- my $label = $dialog->add("Label",-text => $hash{-title},-height => 2,-font => '{fixed} 20 {bold}',-borderwidth => 2,</p><p> -relief => 'groove')->pack(-fill => 'x');
- my $listbox = $dialog->add("Scrolled","Listbox",
- -scrollbars => 'e',
- -selectmode => $hash{-selectmode},
- -borderwidth => 2,
- -height => $hash{-height},
- -width => $hash{-width}
- )->pack(-fill => 'both');
- $listbox->insert('end',@{$hash{-list}});
- my $item = $dialog->Show();
- if ($item eq 'OK'){
- if ($hash{-selectmode} eq 'single') {
- return $hash{-list}->[$listbox->curselection()->[0]];
- }else{
- my @return;
- push @return,$hash{-list}->[$_] for @{$listbox->curselection()};
- return \@return;
- }
- }else{
- exit;
- }
- }
- </p></p>
复制代码 |
|