1 2 3 4 5 6 7 8 9 10 11 12 13 14
$listbox = $mw -> Listbox (-selectmode => "single") -> pack(); $optionmenu = $mw -> Optionmenu (-options => [qw/foo bar bla blubb/] -variable => \$var, -command => \&subfunktion ) -> pack(); sub subfunktion{ opendir (FOO, "/usr/share/$var") || die "öffnen: $!"; @foo = readdir FOO; closedir FOO || die "schließen: $!"; foreach $bar (@foo){ $listbox -> insert ('end', '$bar'); } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
XS_Tk__Callback_Call error:Can't call method "insert" on an undefined value at /etc/perl/chefkoch/list.pm line 30.
Tk::Error: Can't set -options to `ARRAY(0x9d8bd88)' for Tk::Optionmenu=HASH(0x9dcffe0): Can't call method "insert" on an undefined value at /etc/perl/chefkoch/list.pm line 30.
at /usr/lib/perl5/Tk/Derived.pm line 294
at /usr/lib/perl5/Tk/Derived.pm line 306
Tk callback for .frame2
Tk::Derived::configure at /usr/lib/perl5/Tk/Derived.pm line 306
Tk::Widget::new at /usr/lib/perl5/Tk/Widget.pm line 205
Tk::Widget::__ANON__ at /usr/lib/perl5/Tk/Widget.pm line 256
main::list_1 at /etc/perl/chefkoch/list.pm line 15
main::list at ck1.3_main.plx line 61
Tk callback for .frame1.button1
Tk::__ANON__ at /usr/lib/perl5/Tk.pm line 250
Tk::Button::butUp at /usr/lib/perl5/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)
-command => \&subfunktion
(-options => [[jan=>1], [feb=>2], [mar=>3], [apr=>4]])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/perl use Tk; use strict; my ($var, $datei); my $mw = new MainWindow; $mw -> Label (-text => "nur ein kleines Beispiel") -> pack(); my $optionmenu = $mw -> Optionmenu (-options => [qw/perl perl5 php5/], -variable => \$var, -command => \&subfunktion) -> pack(); my $listbox => $mw -> Listbox (-selectmode => "single", -height => 5) -> pack(); MainLoop; sub subfunktion{ opendir (VAR, "/usr/share/$var") || die "öffnen fehlgeschlagen: $!"; my @inhalt = readdir VAR; closedir VAR; foreach $datei (@inhalt){$listbox -> insert ('end', "$datei");} }