I'm writing this program in Perl/Tk and I need to be able to pass a top-level widget to a function. Here is an example of what I mean:
sub start {
my $mw = MainWindow->new;
my $button = $mw->Button(-text=>"Go To Foo", -command => sub {foo($mw);})->pack;
}
sub foo {
my ($parent) = @_;
my $new_window = $parent->new;
}
So, what I'm trying to do here is if a use clicks a button, it will pass the scalar containing the top-level widget to a function which will then create a new window with the top-level widget as the parent. This code obviously doesn't work. It generates this error:
Tk::Error: Can't locate object method "apply_command_line" via package "MainWindow=HASH(0x20761764)" (perhaps you forgot to load "MainWindow=HASH(0x20761764)"?) at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk/MainWindow.pm line 57.
Tk callback for .frame.button
Tk::__ANON__ at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk.pm line 225
Tk::Button::butUp at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk/Button.pm line 111
(command bound to event)
Does anyone know anything about this?
sub start {
my $mw = MainWindow->new;
my $button = $mw->Button(-text=>"Go To Foo", -command => sub {foo($mw);})->pack;
}
sub foo {
my ($parent) = @_;
my $new_window = $parent->new;
}
So, what I'm trying to do here is if a use clicks a button, it will pass the scalar containing the top-level widget to a function which will then create a new window with the top-level widget as the parent. This code obviously doesn't work. It generates this error:
Tk::Error: Can't locate object method "apply_command_line" via package "MainWindow=HASH(0x20761764)" (perhaps you forgot to load "MainWindow=HASH(0x20761764)"?) at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk/MainWindow.pm line 57.
Tk callback for .frame.button
Tk::__ANON__ at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk.pm line 225
Tk::Button::butUp at /usr/local/pkg/perl/perl-5.6.1/lib/site_perl/5.6.1/aix/Tk/Button.pm line 111
(command bound to event)
Does anyone know anything about this?