On 5/3/07, Somu <[EMAIL PROTECTED]> wrote:
Lets say, i have an image at E:/icons/ttt so, how do i show it on a
button created using Tk. I tried to learn from the widget application,
but they have some specific folder, INC or something..

You can create inline images with XPM files:

#!/usr/bin/perl

use strict;
use warnings;
use Tk;

my $mw     = Tk::MainWindow->new;
my $button = $mw->Button->pack;
my $x      = $mw->Pixmap(
       -data => qq(/* XPM */
static char * x_xpm[] = {
"24 24 2 1",
"       c None",
".      c #000000",
"                        ",
"                        ",
"                        ",
"                        ",
"                        ",
"                        ",
"       ...    ...       ",
"        ..    ..        ",
"        ...  ..         ",
"         .. ...         ",
"          ....          ",
"          ...           ",
"          ...           ",
"          ....          ",
"         .. ..          ",
"        ...  ..         ",
"        ..   ...        ",
"       ..     ..        ",
"      ...     ...       ",
"                        ",
"                        ",
"                        ",
"                        ",
"                        "};
));
my $o      = $mw->Pixmap(
       -data => qq(/* XPM */
static char * o_xpm[] = {
"24 24 2 1",
"       c None",
".      c #000000",
"                        ",
"                        ",
"                        ",
"                        ",
"                        ",
"                        ",
"         ......         ",
"        ........        ",
"       ...    ...       ",
"       ..      ..       ",
"      ..        ..      ",
"      ..        ..      ",
"      ..        ..      ",
"      ..        ..      ",
"      ..        ..      ",
"       ..      ..       ",
"       ...    ...       ",
"        ........        ",
"         ......         ",
"                        ",
"                        ",
"                        ",
"                        ",
"                        "};
));

my @toggle = ($x, $o);

$button->configure(
       -image => $x,
       -command => sub {
               @toggle = @toggle[1, 0];
               $button->configure(-image => $toggle[0]);
       }
);

Tk->MainLoop;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to