in reply to How Do I Change A Button Image in Perl TK?

You need to create a Photo object and use this in the -image options: Untested:
$p = $mw->Photo(-file => "example.xpm"); $mw->Button(-image => $p, ...);
If you use xpm then you can also use Pixmap instead of Photo (but this is really only needed if you're short on memory and use big and many pixmaps).

Replies are listed 'Best First'.
Re^2: How Do I Change A Button Image in Perl TK?
by boby_drack (Acolyte) on Jun 11, 2004 at 00:20 UTC
    Yes ! i know this. i've said :" don't examin my syntax !".Even if i use 'Photo' my procedure don't do that i want ! i just want change button's picture during the program run ! thanks man
    that many ways to do it (sic !)
      If you want to change the picture, then do
      $button->configure(-image => $photo_object);
      where $photo_object is constructed with $mw->Photo or $mw->Pixmap. And do not forget to delete unused photo objects, otherwise you'll got a memory leak. Another alternative is to change the filename in the photo object:
      #!/usr/bin/perl use Tk; $mw = tkinit; $p = $mw->Photo(-file => Tk->findINC("Xcamel.gif")); $b = $mw->Button(-image => $p, -command => sub { $p->configure(-file => Tk->findINC("openfolder.xpm")); })->pack; MainLoop;