in reply to Tk::JPEG

You can't attach a Photo to a MainWindow (Correction: Yes, you can, see Jouke's great example "below"). It needs to belong to a Label or a Button or a Text widget (and probably others).

my $mw = MainWindow->new; my $button = $mw->Button()->pack(); my $photo = $button->Photo( -format => 'jpeg', -file => 'test.jpg' ); $button->configure( -image => $photo ); MainLoop;

See also the perldoc for Tk::Photo, it's infinitely more useful than the docs for Tk::JPEG.

Update: now tested, added configure method, without which Tk never realizes it's supposed to be the -image for $button.

Replies are listed 'Best First'.
Re: (ichimunki) Re: Tk::JPEG
by Amoe (Friar) on Aug 14, 2001 at 14:00 UTC
    Aha. I thought it was something obvious, and I had probably read the wrong docs...*hits self* Thanks a lot.
Re: (ichimunki) Re: Tk::JPEG
by Jouke (Curate) on Aug 16, 2001 at 12:20 UTC
    And of course you can define all of this at once:
    my $mw = MainWindow->new; my $photo = $button->Photo( -format => 'jpeg', -file => 'test.jpg' ); my $button = $mw->Button(-image => $photo)->pack(); MainLoop;


    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
      I think it's a little strange to call a method on $button before you have declared $button with my $button. Maybe you patched your parser with a lookahead feature, "hey, do I declare this later, if so I can use it now, right?" :)
        Brrr...you're right! I was way too quick with my answer! It should be this:
        my $mw = MainWindow->new; my $photo = $mw->Photo( "photo" -format => 'jpeg', -file => 'test.jpg' ); my $button = $mw->Button(-image => "photo")->pack(); MainLoop;


        Jouke Visser, Perl 'Adept'
        Using Perl to help the disabled: pVoice and pStory