meraxes has asked for the wisdom of the Perl Monks concerning the following question:
I humbly submit another question to the monks.
I'm in the middle of learning perltk and I must admit to some confusion. I was attempting to create another window in this simple example using the TopLevel method. Alas, it does not work. I'm running this on a Win2k machine using ActiveState Perl v.5.6.1 build 626. The Perltk module was installed using their ppm utility.
Here's my code:
#!/usr/bin/perl -w use strict; use Tk; require Tk::TopLevel; sub newWindow(); sub closeWindow(); my $TestWindow; my $main = MainWindow->new(); $main->Button( -text => "Click Me", -command => \&newWindow)->pack(); MainLoop; sub newWindow () { $TestWindow = $main->TopLevel(); $TestWindow->Label ( -text => "I want to make a new toplevel win +dow!")->pack(); $TestWindow->Button( -text => "Close Me", -command => \&closeWindow)->pack(); } sub closeWindow() { $TestWindow->destroy(); }
Now, the ruddy thing compiles just fine. However at runtime it produces the following errors (which make precious little sense to me):
Subroutine Tk_cmd redefined at D:/Perl/site/lib/Tk/TopLevel.pm line 14 +. Subroutine CreateOptions redefined at D:/Perl/site/lib/Tk/TopLevel.pm +line 17. Subroutine Populate redefined at D:/Perl/site/lib/Tk/TopLevel.pm line +22. Subroutine Icon redefined at D:/Perl/site/lib/Tk/TopLevel.pm line 29. Subroutine menu redefined at D:/Perl/site/lib/Tk/TopLevel.pm line 64. Subroutine Toplevel redefined at D:/Perl/site/lib/Tk/Widget.pm line 24 +7. Assuming 'require Tk::TopLevel;' at D:\Work\test2.pl line 22 Tk::Error: Failed to AUTOLOAD 'Tk::Widget::TopLevel' at D:\Work\test2. +pl line 22 Carp::croak at D:/Perl/lib/Carp.pm line 119 Tk::Widget::__ANON__ at D:/Perl/site/lib/Tk/Widget.pm line 338 main::newWindow at D:\Work\test2.pl line 22 [\&main::newWindow] Tk callback for .button Tk::__ANON__ at D:/Perl/site/lib/Tk.pm line 228 Tk::Button::butUp at D:/Perl/site/lib/Tk/Button.pm line 111 (command bound to event)
Where is my problem here? The Code? The installation of the module? I must admit, that I find the online information on PerlTk to be sparse (Found the FAQ, found the docs at CPAN) and more than a little confusing for me. I learn best by seeing examples. Any help/explanation would be greatly appreciated.
|\/|eraxes
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perltk and TopLevel
by ariels (Curate) on May 21, 2002 at 15:08 UTC | |
by meraxes (Friar) on May 21, 2002 at 15:28 UTC | |
by bmcatt (Friar) on May 21, 2002 at 16:31 UTC | |
by meraxes (Friar) on May 21, 2002 at 16:48 UTC | |
by jerryk (Initiate) on Oct 20, 2013 at 14:38 UTC | |
by Khen1950fx (Canon) on Oct 21, 2013 at 04:51 UTC |