Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I have looked at the Tk faq and am still stumped on this one.

I'm trying to draw a canvas and place a gif file upon said canvas.

Going to the Tk faq and replacing the file, I have the following code:

#!/usr/bin/perl -w use strict; use Tk; my $main = new MainWindow; my $canvar = $main ->Canvas; $canvar->pack; my $file = 'c:\html\atomic\0.gif'; my $img = $canvar->Photo( 'IMG', -file => Tk->findINC($file) ); $canvar->create( 'image',0,0, '-anchor' => 'nw', '-image' => $img ); MainLoop; __END__

What I'm getting is a lovely canvas, but no picture.

At present I'm working on a windows machine and will have do demo this on a windows machine, so my questions are:

  1. Do I have the file path wrong? Is perl not understanding that?
  2. Is there something else wrong with the code there that I'm not seeing?
  3. Why place the __END__ after MainLoop with nothing going on? I thought code placed below MainLoop would execute for cleanup or whatever anyway.

Thanks for any and all help on this one. Sometimes getting your interface right is worse than the underlying code to make it all work. :)

Replies are listed 'Best First'.
Re: YATkQ ( yet another Tk question)
by converter (Priest) on Apr 28, 2002 at 20:12 UTC

    &Tk::findINC searches the paths listed in @INC for a file. Since you're supplying a complete pathname for the image file, you should probably forego the call to &findINC.

    This should work just fine:

    my $img = $canvar->Photo( 'IMG', -file => $file );

    conv

Re: YATkQ ( yet another Tk question)
by DigitalKitty (Parson) on Apr 28, 2002 at 21:12 UTC
    Hi Popcorn Dave.

    Did you use CPAN to obtain the module? When I tried to d/l it, I received an error code of 512. The make failed. Did you have any problems? If so, how did you solve them? Any suggestions? I'm going crazy!

    Thanks,

    -DK.
      No, actually I didn't. I've been using ActiveState's Perl, so if you have an older version that could be a problem. I had one that was build 630 and there was a problem ( which escapes me now ) but when I did the upgrade to 631, all was fine.
Re: YATkQ ( yet another Tk question)
by rbc (Curate) on Apr 29, 2002 at 04:23 UTC
    ... mmm I haven't done much with images and canvas in Tk
    but do you need to "->pack();" your widgets?
      I haven't played much with Tk either, but I'm learning :)

      But to answer your question, it depends on what you're doing, and I haven't quite figured out the "to pack or not to pack" widget rules yet.