Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Tk::Photo and copy method

by didier (Vicar)
on Aug 01, 2003 at 19:02 UTC ( #280103=perlquestion: print w/replies, xml ) Need Help??
didier has asked for the wisdom of the Perl Monks concerning the following question:


I am experiencing a problem that I canno't solve.
It's about the data of the copy method in Tk::Photo.
Sorry for the length: I canno't have readmore tags working. Bad day.
Here a sample script:
use Tk; use strict; # a nice and stolen pic my $dilbert = <<"EOXPM"; /* XPM */ static char *smalldilbert[] = { " 16 16 14 1", /* colors */ "` c #000000", ". c #380000", "# c #383800", "a c #383838", "b c #790000", "c c #793838", "d c #797938", "e c #797979", "f c none", "g c #bebe38", "h c #bebe79", "i c #ffff79", "j c #bebebe", "k c #ffffff", /* pixels */ "fff`dd##aadd`fff", "ffff`iiiiii`ffff", "ffff`iiiiii`ffff", "ffff`ihghgi`ffff", "fff``deeeed``fff", "fffdaiededi#dfff", "fffa`iighii`#fff", "ffff`idiidi`ffff", "ffff`igddhi`ffff", "ffff`iiiiii`ffff", "ffff`iiiiii`ffff", "ffffaeedddeaffff", "fff`eee.`eee`fff", "ff`jjck.bkkkj`ff", "f`jkb.a.`kkkkj`f", "`jjj``...kkkjjj`" }; EOXPM # making a empty image my $mw = MainWindow -> new; my $label = $mw->Label ()->pack; my $image = $label ->Photo('image', -height => 10, -width => 10, -format=>'XPM'); $label->configure(-image => $image); my $data_mw = $image->data(-format => 'XPM'); # so what we have? print "$data_mw\n"; # this is ok # now making a dilbert image my $top = $mw ->Toplevel; my $label_1 = $top -> Label()->pack; my $image_1 = $label_1 ->Photo('image', -data=> $dilbert, + -format=>'XPM'); $label_1->configure(-image => $image_1); # copying the dilbert inside the empty one # MainLoop auto-update... $image -> copy($image_1); my $data_copy = $image->data(-format => 'XPM'); print $data_copy; # the above print something like # Tk::Photo=HASH(0xc5ef04) # How can I access this data? # Not the original but the copy MainLoop;

Thank for any help.


Replies are listed 'Best First'.
Re: Tk::Photo and copy method
by converter (Priest) on Aug 02, 2003 at 05:22 UTC

    Tk::Photo supports the following formats:

    • BMP
    • PPM
    • GIF
    • PNG (with extension)
    • JPEG (with extension)
    • TIFF (with extension)

    Try using Tk::Pixmap (which supports only XPM) instead.


      I have found the problem.

      An empty photo object must be set without explicit
      descriptor, nor image tags.
      So in the main window, the line:
      my $image = $label ->Photo('image', -height => 10, -width => 10, -format=>'XPM');
      my $image = $label ->Photo( -height => 10, -width => 10);
      Nice day for you all!
      Thank for the answer, converter.
      As you see in the code above, my problem relie on the usage
      of the copy method from Tk::Photo.
      Tk::Pixmap has no method which allows partial pixels
      You can only cget() or configure() the whole.

      But more specifically my question was:
      what's means this "Tk::Photo=HASH(0xc5ef04)"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://280103]
Approved by Thelonius
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-06-23 10:04 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.