I have no idea why. There is no code in the button command that even mentions the items for the first Canvas.
Any guidance is greatly appreciated. Thank you for reading.
use strict; use warnings; use Tk; # Create Main Window my $mw = MainWindow -> new; $mw->bind('<Escape>' => sub { $mw->destroy(); }); # Letter A in XPM format my $LtrA = '/* XPM */ static char * a[] = { "8 8 2 1", " c none", "x c #000000", " xx ", " xxxx ", " xx xx ", "xx xx", "xxxxxxxx", "xxxxxxxx", "xx xx", "xx xx"};'; # Letter B in XPM format my $LtrB = '/* XPM */ static char * b[] = { "8 8 2 1", " c none", "x c #000000", "xxxxxxx ", "xxxxxxxx", "xx xx", "xxxxxxx ", "xx xx", "xx xx", "xxxxxxxx", "xxxxxxx "};'; # Image A holder in Main Window my $LblA = $mw->Label(-text => 'Image A:')->pack(); my $cvsA = $mw->Canvas(-background=>'yellow', -height => 40, -width => + 40)->pack(); # Image B holder in Main Window my $LblB = $mw->Label(-text => 'Image B:')->pack(); my $cvsB = $mw->Canvas(-background=>'green', -height => 40, -width => +40)->pack(); # Set Image A my $imgA = $mw->Photo('image', -data => $LtrA); $cvsA->create('image', 10, 10, -image => $imgA); # Button to make Image B my $btn = $mw->Button(-text => 'Add Letter B', -command => \&Add_B)->p +ack(-pady => 5); MainLoop; sub Add_B { my $imgB = $mw->Photo('image', -data => $LtrB); $cvsB->create('image', 30, 30, -image => $imgB); }
In reply to Tk::Photo XPM images being copied by Kaughper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |