Perl Tk::Photo help

Discussion in 'Scripts, 3rd Party Apps, and Programming' started by cerbere, Dec 11, 2008.

  1. cerbere

    cerbere New Member

    Hi everyone,

    I'm trying to use the Tk::photo class, but the documentation
    is very scarse. All I can find is

    http://search.cpan.org/dist/Tk/pod/Photo.pod

    with it's strange syntax like

    $widget->Photo(?name??, options?)

    and no examples of use at all.
    The following code works, but I have no idea why I must
    put the Photo into a Label :

    Code:
    use Tk;
    use Tk::JPEG;
    my $MW = new MainWindow;
    
    $MW ->Label(-text => 'Tk Photo')->pack;
    $image_tk = $MW->Photo('img', -format=>'jpeg', 
                       -file => "c:/someimage.JPG");
    $MW->Label(-image => $image_tk)->pack(-side=>'left');
    
    $MW->Button(-text => 'exit',
                -command => sub{exit} )
       ->pack(-side => 'bottom');
    MainLoop;
    
    Anyone knows a friendlier intro to Tk::photo ?
    A cookbook maybe ?

    As the Perl doc often reminds me, I'm a poor loser
    forced to program on a Win32 box... :pigeon:)

    Thanks for any help !
  2. vol7ron

    vol7ron New Member

    Basically, you ad whatever you add stuff to a label or other class (see second link), and then pack/display it. The second link is probably my favorite for reference of the ones I've found. The third has some okay sample code.

    http://www.lehigh.edu/~sol0/ptk/perlmonth01/pm1.html
    http://www.ida.liu.se/~tompe/perltk/index.html
    http://www.geocities.com/binnyva/code/perl/perl_tk_tutorial/


    This link is probably the most helpful to you:
    http://search.cpan.org/src/MARKOV/PPresenter-1.17/doc_html/image/tkphoto.html
    Last edited: Dec 11, 2008
  3. cerbere

    cerbere New Member

    Thanks for the feedback, vol7ron, but I couldn't find any
    help in the references you cited :pigeon:(
  4. vol7ron

    vol7ron New Member

  5. cerbere

    cerbere New Member

    Vol7ron, I am not looking for a Tk tutorial,
    but for specific information (with examples if possible)
    about the Tk::photo object.
  6. vol7ron

    vol7ron New Member

    Well I don't know how simpler you can get than what you've already posted/said.

    Photos
    The perl/Tk Photo() function achieves an effect similar to the Bitmap() function. Namely, it returns a file descriptor to be used in a later -image configuration option to a widget.

    As an example consider the Label widget that uses the 'imggif' descriptor in the following:
    Code:
       #!/usr/bin/perl -w
       use strict;
       use Tk;
       my $main = new MainWindow;
       $main->Photo(
          'imggif'
          , -file  => "$Tk::tk_library/demos/images/earthris.gif"
       );
    
       my $c = $main->Label( '-image'=>'imggif' )->pack;
    
       $main->Button(
          -text    => 'exit',
          -command => sub{destroy $main}
       )->pack(-anchor => 'e');
    
       MainLoop;
    
    img/photo_earthris.gif
    Last edited: Dec 16, 2008
  7. cerbere

    cerbere New Member

    After a lot of Googling, I think I'll manage.

    Please close this thread.
  8. vol7ron

    vol7ron New Member

    at least post what you found. i'm thinking your problem is understanding Perl and not the Tk module.

    the link you gave from cpan gives all the properties of handling an image and all the links i gave you are examples of how to create and add one to a page. forgive me for trying to help and not seeming to answer your concern, but i don't know how else to help.

    if you don't need a tutorial, i take it that you know how to create a photo/image.



    Besides providing more code, this describes everything about the module, I'm not sure what other documentation you could want?

    That's a really small example. So I have you a bunch of sites with examples and tutorials that explain them and then you say you don't need tutorials... that makes no sense

    Again, you asked in different words for a detailed tutorial,which I gave you. Granted, it was on the tk module as a whole, but you weren't understanding that you had to add the image to a widget, so I showed you a tutorial on widgets. how can you do square roots if you don't understand multiplication; meaning, you're not grasping the module and you need to know the other stuff before working with that. i still gave an example of adding the photo to the label widget and in one of my links i showed you the different widgets you can add a photo to.


    please tell me what you found on Google so we can hopefully use it (for ourselves) or to educate people in the future
    Last edited: Dec 19, 2008

Share This Page