Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Tk::Image problem

by CombatSquirrel (Hermit)
on Nov 27, 2003 at 19:17 UTC ( [id://310584]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to get a gif image to be displayed on a Tk::Image widget, but it doesn't work. It does not give any error messages, the problem is just that the image does not show up in the main window. The image does exist, is readable, and its content is different from the look of my window background.
Here is the code:
#!perl -w use strict; use Tk; use Tk::Photo; my $main = new MainWindow; my $photo = $main->Photo(-format => 'gif', -file => 't.gif'); MainLoop;
CombatSquirrel.
Entropy is the tendency of everything going to hell.

Replies are listed 'Best First'.
Re: Tk::Image problem
by holo (Monk) on Nov 27, 2003 at 19:51 UTC

    Forgot to ->pack() your widget and main window!

      I tried that too, but it gives me
      wrong # args: should be "pack option arg ?arg ...?" at t.pl line 9.
      when I use ->pack and
      bad option "image1": must be configure, forget, info, propagate, or sl +aves at t.pl line 9.
      when i use ->pack(-anchor => 'sw')
      Thanks for your response, anyways.
      CombatSquirrel.
      Entropy is the tendency of everything going to hell.

        To make up for my ignorance:

        #!/usr/bin/perl use strict; use Tk; use Tk::Photo; my $main = new MainWindow; my $photo = $main->Photo(-format => 'gif', -file => 't.gif'); my $canvas = $main->Canvas( -width => $photo->width, -height => $photo->height, )->pack( -side => 'top' ); $canvas->createImage(0, 0, -image => $photo, -anchor => 'nw'); MainLoop;

        Tk::Photo is not a widget, just an object that contains the photo. Use a Tk::Canvas to display the photo.

      Oh, the question was, as you undoubtedly guessed, "How do I get it to work". Just posting it here, because I can't edit the root node any more.
      CombatSquirrel.
      Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (1)
As of 2024-04-19 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found