Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Perltk and TopLevel

by meraxes (Friar)
on May 21, 2002 at 14:59 UTC ( [id://168148]=perlquestion: print w/replies, xml ) Need Help??

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

    s/TopLevel/Toplevel/mg;

    "require Tk::TopLevel;" doesn't bomb out because you'd appear to be on a Windows system (file search is case-insensitive). But Tk::TopLevel isn't being found, because it's Tk::Toplevel...

    Oh, and it's probably a better idea to "use Tk::Toplevel;".

      I've tried changing the "require" line as you specified but now I get an extra line in the error codes:

      Assuming 'require Tk::TopLevel;' at D:\Work\test2.pl line 21

      And still no window. :(

        You need to also change the line where you create the new top-level window.

        $TestWindow = $main->Toplevel();

        It's not just the require that needs to change... The /m on ariels' substitution indicated that you needed to change TopLevel->Toplevel everywhere...

      Damn I hate MixedCaseVariableNames. Because I can't remember them as sounds. Is it topLevel or Toplevel or TopLevel? If I wrote the code, it's "top_level". Period. And what if there's an acronym buried in the variable name? Is it CvsVersion or CVSversion? Or - god help us - CVSVersion? When the revolution comes, the inventors of mixed case variable names will be the first against the wall!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://168148]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-20 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found