Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Don't ask to ask, just ask
 
PerlMonks  

Tk on Win32

by spacewarp (Pilgrim)
on Apr 13, 2001 at 06:03 UTC ( #72276=perlquestion: print w/ replies, xml ) Need Help??
spacewarp has asked for the wisdom of the Perl Monks concerning the following question:

The recent discussion regarding Tk reminded me that I have been unable to get the dang GUI working on my system. I'm using ActivePerl 5.6.0 on Win98, and everytime I try to run a program, including the "Hello World" program on page 11 of "Learning Perl/Tk", the program minimizes the command prompt and does nothing else. No errors, no output, nothing.

For easy reference, here's the code:
use Tk; my $mw = MainWindow->new; $mw->title( "Hello World" ); $mw->Button(-text => "Done", -command => sub { exit })->pack; Mainloop;


Any ideas on what's wrong?

Spacewarp

DISCLAIMER:
Use of this advanced computing technology does not imply an endorsement
of Western industrial civilization.

Comment on Tk on Win32
Download Code
Re: Tk on Win32
by Chmrr (Vicar) on Apr 13, 2001 at 06:40 UTC

    Watch the case sensitivity. The following works fine:

    use Tk; my $mw = MainWindow->new; $mw->title( "Hello World" ); $mw->Button(-text => "Done", -command => sub { Tk::exit })->pack; MainLoop;

    Two things to notice -- use Tk::exit to drop out, as it gives Tk time to clean up, etc. Secondly, and most importantly, tis MainLoop, not Mainloop!

    Hope this helps. If not, then you might want to try reinstalling Tk. Also, try running widget.bat, which is included in the Tk install -- you should find it in the same directory that your Perl executable is in. If that doesn't work, it's a sure bet that your install is broken.

     
    perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

      Thank you very much! That was indeed the problem. Time to start playing!!! 8)

      Incidentally, I *love* your sig! 8)

      Spacewarp

      DISCLAIMER:
      Use of this advanced computing technology does not imply an endorsement
      of Western industrial civilization.
Re: Tk on Win32
by atcroft (Monsignor) on Apr 13, 2001 at 06:51 UTC
    I tried running it on ActiveState build 618, and got the same results as you-nothing. So I decided to try it from the command line with -w for warnings, and got:

    C:\WINDOWS\Desktop> perl -w tk1.pl
    Useless use of a constant in void context at tk1.pl line 5.
    Use of uninitialized value in concatenation (.) at C:/Perl/site/lib/Tk.pm line 350.
    Use of uninitialized value in concatenation (.) at C:/Perl/site/lib/Tk.pm line 350.

    Line 5 was the line you have as "Mainloop;" -when I changed this to "MainLoop();", it worked for me. Trying "-w" gave only:

    C:\WINDOWS\Desktop> perl -w tk1.pl
    Use of uninitialized value in concatenation (.) at C:/Perl/site/lib/Tk.pm line 350.
    Use of uninitialized value in concatenation (.) at C:/Perl/site/lib/Tk.pm line 350.

    I did get the button you intended, then.

      A side note -- those warnings of undefined values are Tk looking for a HOME environment variable. Either go in and tweak the source on those lines to make it happy, or set the HOME variable yourself.

       
      perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

        Here's my win95/winME "tweak" (i copy/pasted the whole subroutine that i munged). PS if you don't have multiple logins under win95/ME just change the else{$Home=... to $Home="C:/My Documents", on NT/2000 i'm not to sure...havn't messed with pTK on my NT box yet.

        sub TranslateFileName { local $_ = shift; unless (defined $Home) { unless ($^O eq 'MSWin32'){ $Home = $ENV{'HOME'} || ($ENV{'HOMEDRIVE'}.$ENV{'HOMEPATH'}); } else { $Home = "c:/windows/profiles/" . getlogin() . "/My Documents +"; } $Home =~ s#\\#/#g; $Home .= '/' unless $Home =~ m#/$#; } s#~/#$Home#g; # warn $_; return $_; }

        _________________
        madams@scc.net
        (__) (\/) /-------\/ / | 666 || * ||----||

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-04-20 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls