I replicated your error with your code. I looked at the test suite for Tk in the t/photo.t, and they include use Tk::PNG; use Tk::JPEG; (or equivalent conditional require's), so I successfully tried code with the two extra use statements:

use strict; use warnings; use Tk; use Tk::PNG; use Tk::JPEG; my @arr; push @arr, { name => 'sample.gif', type => 'image/gif'}; push @arr, { name => 'sample.png', type => 'image/png'}; push @arr, { name => 'sample.jpg', type => 'image/jpeg'}; foreach my $fh (@arr) { my $f = $fh->{name}; my $t = $fh->{type}; eval { my $mw = MainWindow->new; my $lbl = $mw->Label; my $photo = $mw->Photo(-file=>$f); #, -format=>$t ); $lbl->configure(-image=>$photo); $lbl->pack; MainLoop; 1; } or do { warn "here: $@\n"; }; }

update: I was curious about the -format, since the mime-types I had tried (based on commented-out code) didn't work. the t/photo.t showed method $photo->formats(), so I printed those => jpeg, png, bmp, xpm, xbm, gif, PPM. So, to get -format to work with my code, it should be as follows (which still works):

use strict; use warnings; use Tk; use Tk::PNG; use Tk::JPEG; my @arr; push @arr, { name => 'sample.gif', type => 'gif'}; push @arr, { name => 'sample.png', type => 'png'}; push @arr, { name => 'sample.jpg', type => 'jpeg'}; foreach my $fh (@arr) { my $f = $fh->{name}; my $t = $fh->{type}; eval { my $mw = MainWindow->new; my $lbl = $mw->Label; my $photo = $mw->Photo(-file=>$f, -format=>$t ); print join ", ", $photo->formats(), "\n"; $lbl->configure(-image=>$photo); $lbl->pack; MainLoop; 1; } or do { warn "here: $@\n"; }; }

In reply to Re: Displaying PNG and JPG images using Tk on Windows by pryrt
in thread Displaying PNG and JPG images using Tk on Windows by skleblan

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.