Greetings Exalted Monks!
Below is a code that shows two Canvases ("Canvasi"?), the first with a XPM image of the letter "A", the second empty.
When the button at the bottom is clicked, the second Canvas is supposed to have an XPM image of the letter "B" placed into it.
That much happens, but the weird thing is that the image in the FIRST Canvas is ALSO changed to the letter "B".

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.