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


In reply to Perltk and TopLevel by meraxes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.