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

Hi,
I'm trying to open up a dialog box with an image in it in perltk. I've tried just about everything but nothing works.. Heres the piece of code I'm trying to work with:
my $dialog_about = $main_window->DialogBox( -title => "About $program_title",); $image = $main_window->Photo ( -file => 'aboutIE.bmp', -height => 413, width => 289);

So all I'm basically trying to do is put an image into a dialog box, the actual GUI around it works but when I click the menu button to open that dialog box (using the above code) it comes up with an error message:

Tk::Error: Can't locate auto/Tk/Photo/Show.al in @INC
(@INC contains: C:/Perl/lib C:/Perl/site/lib .) at tk.pl line 98
\&main::__ANON__
(menu invoke)


If anyone can please lead me in the correct direction, that'd be greatly appreciated, thanks! :)

Replies are listed 'Best First'.
Re: Images in Perl/Tk Dialog Box
by Plankton (Vicar) on Jun 03, 2004 at 17:33 UTC
    I think you might need a Canvas ...
    $ cat image.pl #!/usr/bin/perl -w use strict; use Tk; use Tk::Canvas; my $width = 250; my $height = 250; my $top = MainWindow->new(); my $photo = $top->Photo(-file => "me.bmp" ); my $can = $top->Canvas( -width => $width, -height=> $height )->pack(); $can->createImage(100, 100, -image => $photo ); MainLoop;

    Plankton: 1% Evil, 99% Hot Gas.
Re: Images in Perl/Tk Dialog Box
by Grygonos (Chaplain) on Jun 03, 2004 at 17:53 UTC

    You will also need to create the photo and canvas widgets as part of your dialogbox. ie it should read

    my $dialog_about = $main_window->DialogBox( -title => "About $program_title",); $image = $dialog_about->Photo ( -file => 'aboutIE.bmp', -height => 413, width => 289);
    and a similar declaration for your canvas widget.

Re: Images in Perl/Tk Dialog Box
by eserte (Deacon) on Jun 03, 2004 at 19:09 UTC
    Tk::Error: Can't locate auto/Tk/Photo/Show.al in @INC
    Why are you doing $image->Show? I think you want something like $dialog_about->Label(-image => $image)->pack instead.
      Thanks a lot guys! I got everything working ok :)