http://qs321.pair.com?node_id=726048


in reply to Images in Canvas

You use my $xpm two times, I think one of that lines should be commented out.

In different to the createBitmap method you do not need to put a @ in front of the image name when using createImage, if I understand "Mastering Perl/TK" the right way.

Perhaps try one of the built in bitmaps first, to be shure to have no problems with the bitmap file, e.g. my $xpm = $drawing->createBitmap(0, 0, -bitmap  => 'info');.

In case of the createImage method, you have to use an object created with the Photo or Bitmap methods.


I tested a little bit and ending with this, perhaps it is a source for an idea for you:

#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = new MainWindow; $mw->geometry('600x600+110+110'); my $drawing = $mw->Canvas( -width => 500, -height => 500, -background => 'white', )->pack(); my $xpm = <<'END'; /* XPM */ static char *test[]={ "32 32 11 1", ". c None", "# c #000000", "h c #004000", "g c #004040", "f c #404000", "e c #808080", "i c #a0a0a4", "c c #c0c000", "d c #ffff00", "b c #ffffc0", "a c #ffffff", "................................", "................................", "................................", "................................", ".............#....###...........", "............#a##.#aba##.........", "...........#aaaa#aaaaaa##.......", "..........#aaaa#aaaaaaaba##.....", ".........#aaaa#aaaaaaaaaaab##...", "........#aaba#aaaaaaabaabaaaa##.", ".......#aaba#baaaaa#baaaaaabaaa#", "......#aaaa#aaaaab#a##baaaaaaa#.", ".....#aaba#aacbba#aaaa##baaab#..", "....#bbaa#abaacc#aaaaaaa##aa#...", "...#bbbb#aaabaa#aaabaaaaaa##....", "..#bbbb#bacaaa#aaaaaaaabaaaa##..", ".#bbbb#bbaacc#aacaaaaaaaaaaaba#.", "#ddbb#bbbbba#aaaaccaaaaaaaaaaaa#", "#edddfgcbbbfaacaaaaccaaaaaaaaa#e", ".#hedddfhcfabaaccaaabccaaaaaa#e.", "...##edddhaacbbaaccbaaaccaab#i..", ".....##e#baaaccabaaccbaabaa#i...", "......##bacbaabccbaaaccabb#e....", "......#bbbbccaabbccaaaaab#i.....", ".....#bbbbbbbccabbaccaab#i......", ".....#ebbbbbbbbccbaabba#i.......", "......##ebbbbbbbbccaabhe........", "........##ebbbbbbbbbb#e.........", "..........##ibbbbbbbhe..........", "............##ebbbb#e...........", "..............#hee#i............", "................##i............."}; END my $bitmap = $mw->Pixmap(-data => $xpm); $drawing->createImage(100, 100, -image => $bitmap); MainLoop();