Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to change the TK Icon that is displayed?

195 views
Skip to first unread message

Chris

unread,
Feb 6, 2002, 4:14:29 PM2/6/02
to
I want to change the default Tk icon that is displayed in the SysTray and in
the Title bar of the app.

Is there a way to change this, per program?

TIA!

--
Chris Anderson
CTO
C&P Enterprises
http://www.candp-ent.com/


Christoph Fuchs

unread,
Feb 7, 2002, 3:04:21 AM2/7/02
to
Chris wrote:
>
> I want to change the default Tk icon that is displayed in the
> SysTray and in
> the Title bar of the app.
>
> Is there a way to change this, per program?
>

Use the $toplevel->iconbitmap or iconimage method (see perldoc Tk::Wm).
I don't know if this works on all operating systems and window managers,
but at least it works on all that I use.

Marc Dashevsky

unread,
Feb 7, 2002, 7:12:12 AM2/7/02
to
In article <V0h88.2873$OI4.48...@newssvr15.news.prodigy.com>,
qab...@prodigy.net says...

> I want to change the default Tk icon that is displayed in the
> SysTray and in the Title bar of the app.
>
> Is there a way to change this, per program?

use Tk;
my $mw = tkinit;
my $image = 'foo.gif'; # 32x32 GIF or BMP
my $icon = $mw->Photo(-file => $image);
$mw->idletasks; # this line is crucial
$mw->iconimage($icon);
MainLoop;

--
Marc Dashevsky -- Remove '_' from address if replying by e-mail.

Tom Baker

unread,
Feb 7, 2002, 10:32:52 AM2/7/02
to
This only works on Unix compatible OS. NOT Win32!!

Marc Dashevsky

unread,
Feb 7, 2002, 10:59:44 AM2/7/02
to
In article <3C629E24...@ntlworld.com>, tom.b...@ntlworld.com says...

> This only works on Unix compatible OS. NOT Win32!!

It works fine under Windows 2000. I test everything before
I post. Did you actually run what I posted? Tell us what
happens on your system.

Chris

unread,
Feb 7, 2002, 11:13:07 AM2/7/02
to
Does the pic HAVE to be either a BMP or JPG???
I get an error that it can't find the ICO file...


"Marc Dashevsky" <m_...@world.std.com> wrote in message
news:MPG.16cc6ead1...@netnews.attbi.com...

Steve Roscio

unread,
Feb 7, 2002, 11:15:08 AM2/7/02
to
We use Mark's method on WNT and W2K; it works just fine. Also works on
UNIX/Linux too.


Steve Roscio

unread,
Feb 7, 2002, 11:16:42 AM2/7/02
to
I have not tried an ICO, but I know that GIF and BMP work OK on a variety of
platforms, including Windows NT and 2000.

"Chris" <qab...@prodigy.net> wrote in message
news:nIx88.22194$D_7.340...@newssvr16.news.prodigy.com...

Chris

unread,
Feb 7, 2002, 11:41:19 AM2/7/02
to
OK! It doesn't like ICO files! :)

But it WILL do a GIF file.

Using Perl2EXE is there anyway to embed THAT gif into the exe so I am
distributing only 1 file???

:)

TIA!

"Steve Roscio" <steve....@compaq.c-o-m> wrote in message
news:jKx88.645$am1....@news.cpqcorp.net...

Marc Dashevsky

unread,
Feb 7, 2002, 12:49:02 PM2/7/02
to
In article <P6y88.22396$_u.3410...@newssvr16.news.prodigy.com>,
qab...@prodigy.net says...

> OK! It doesn't like ICO files! :)
>
> But it WILL do a GIF file.
>
> Using Perl2EXE is there anyway to embed THAT gif into the exe so I am
> distributing only 1 file???

I've done the following with bitmaps. I'm almost certain you can
do something similar with GIFs.

my $triangle = "#define triangle_width 11
#define triangle_height 16
static char triangle_bits[] = {
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xfe, 0x03, 0xfc, 0x01,
0xf8, 0x00, 0x70, 0x00,
0x20, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
";
my $arrow = $Top->Bitmap(-data => $triangle);

Chris

unread,
Feb 7, 2002, 1:20:31 PM2/7/02
to
WHOA!

Just blew me right out of the water! :)

Care to put that one in English? ;P

I have a 32X32X256 GIF that I am using for the image file... :)

Thanks...

Chris

"Marc Dashevsky" <m_...@world.std.com> wrote in message

news:MPG.16cc8849d...@netnews.attbi.com...

H. Wade Minter

unread,
Feb 7, 2002, 12:58:59 PM2/7/02
to
Marc Dashevsky <m_...@world.std.com> wrote:
> I've done the following with bitmaps. I'm almost certain you can
> do something similar with GIFs.

> my $triangle = "#define triangle_width 11
> #define triangle_height 16
> static char triangle_bits[] = {
> 0x00, 0x00, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> 0xfe, 0x03, 0xfc, 0x01,
> 0xf8, 0x00, 0x70, 0x00,
> 0x20, 0x00, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00,
> 0x00, 0x00, 0x00, 0x00
> };
> ";
> my $arrow = $Top->Bitmap(-data => $triangle);

Mastering Perl/Tk (p. 427) shows that if you use a binary image format
like GIF, and you want to embed it in your code like the above bitmap,
you have to base64 encode the data into a string. You can then reference
the string with -data.

--Wade

Slaven Rezic

unread,
Feb 7, 2002, 2:32:42 PM2/7/02
to
Christoph Fuchs <Christo...@ipp.mpg.de> writes:

FYI, it does not work with fvwm2. Instead you have to add a line in
your .fvwm2rc config file.

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

tkrevdiff - graphical display of diffs between revisions (RCS or CVS)
http://ptktools.sourceforge.net/#tkrevdiff

Slaven Rezic

unread,
Feb 7, 2002, 2:35:15 PM2/7/02
to
Marc Dashevsky <m_...@world.std.com> writes:

> In article <P6y88.22396$_u.3410...@newssvr16.news.prodigy.com>,
> qab...@prodigy.net says...
> > OK! It doesn't like ICO files! :)
> >
> > But it WILL do a GIF file.
> >
> > Using Perl2EXE is there anyway to embed THAT gif into the exe so I am
> > distributing only 1 file???
>
> I've done the following with bitmaps. I'm almost certain you can
> do something similar with GIFs.

Yes, it works. For gif, the -data string have to be base64 encoded.

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

babybike - routeplanner for cyclists in Berlin
handheld (e.g. Compaq iPAQ with Linux) version of bbbike
http://bbbike.sourceforge.net

Slaven Rezic

unread,
Feb 7, 2002, 2:34:10 PM2/7/02
to
"Chris" <qab...@prodigy.net> writes:

> Does the pic HAVE to be either a BMP or JPG???
> I get an error that it can't find the ICO file...

It should be a photo format supported by Tk, that is GIF, PPM, XPM,
BMP (and with additional modules PNG, JPEG, TIFF). ICO is not
supported.

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

tkrevdiff - graphical display of diffs between revisions (RCS or CVS)
http://ptktools.sourceforge.net/#tkrevdiff

Slaven Rezic

unread,
Feb 7, 2002, 4:28:45 PM2/7/02
to
Marc Dashevsky <m_...@world.std.com> writes:

> In article <Pzz88.22450$6l2.341...@newssvr16.news.prodigy.com>,
> qab...@prodigy.net says...


> > WHOA!
> >
> > Just blew me right out of the water! :)
> >
> > Care to put that one in English? ;P
>

> Let me direct you to Wade's reply. As he suggests, I'm looking
> at page 427 in Lidie & Walsh's MASTERING PERL/TK. It shows how
> to use MIME::Base64 to encode your 32x32x256 GIF file. You then
> would use something like the following code:


>
> use Tk;
> my $mw = tkinit;

> my $imagedata = A STRING CONTAINING A BASE64 ENCODING OF THE GIF
> my $icon = $mw->Photo(-data => $imagedata, -format => 'gif');


> $mw->idletasks; # this line is crucial
> $mw->iconimage($icon);
> MainLoop;
>

> To be honest, I couldn't get a GIF to work, either from a data string
> or from a file. I get an all-black icon. If this is what Tom Baker
> was referring to, I would love to see how to do this with the Icon
> method.

Maybe a Perl/Tk together with Windows problem? It works with Unix (KDE2).

Regards,
Slaven

--
Slaven Rezic - slaven...@berlin.de

Stephen O. Lidie

unread,
Feb 7, 2002, 8:06:11 PM2/7/02
to
>> Does the pic HAVE to be either a BMP or JPG???
>> I get an error that it can't find the ICO file...

> It should be a photo format supported by Tk, that is GIF, PPM, XPM,
> BMP (and with additional modules PNG, JPEG, TIFF). ICO is not
> supported.

It can also be a Unix X11 bitmap (class Bitmap, extension=xbm), or a
Pixmap (Class Pixmap, extension=xpm).

You can create a Photo of a .xbm file (rather than a Bitmap), or a Photo
of a .xpm file (rather than a Pixmap), but a Photo of a bitmap/pixmap
file uses more resources than an object of class Bitmap/Pixmap.

Kevin Michael Vail

unread,
Feb 9, 2002, 3:19:08 AM2/9/02
to
In article <MPG.16cc6ead1...@netnews.attbi.com>, Marc
Dashevsky <m_...@world.std.com> wrote:

> In article <3C629E24...@ntlworld.com>, tom.b...@ntlworld.com says...
> > This only works on Unix compatible OS. NOT Win32!!
>
> It works fine under Windows 2000. I test everything before
> I post. Did you actually run what I posted? Tell us what
> happens on your system.

I'm not the OP, but it works fine on Win98.

--
Kevin Michael Vail | a billion stars go spinning through the night,
ke...@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)

David de Gendt

unread,
Feb 27, 2002, 4:30:38 AM2/27/02
to
"Chris" <qab...@prodigy.net> wrote in message news:<nIx88.22194$D_7.340...@newssvr16.news.prodigy.com>...

I tried to run exactly what you posted (under win2000) and the icon is
not being displayed correctly; it just shows a white icon for a bitmap
and a black one when using a gif format. I checked that I have
Tk::Photo - any suggestions?

Cary Millsap

unread,
Jun 21, 2002, 11:30:50 PM6/21/02
to
I use "encode.pl" shown at bottom to convert a .gif into MIME64 (e.g., "C>
perl encode.pl warning.gif >warning.m64"). Then I can read the MIME64
content directly into my source:

...
$data{error} = <<EOF;
R0lGODlhIgAiAKIAANnZ2YQAAP8AAISEhP///////////////yH5BAEAAAAALAAAAAAiACIA
AAP/CLrc/jACFLqKoMvtikJRdDUCA0GXmzFQdJkDQZcbMAJFl1swAkGXN1B0uRsDQZchUHS5
XVAg6HKg6HK7oBgEXQ0UXdpdgQhFNwZBN1B0iQhFV4mQUHQDQTdQVJFUUXSRVFFUYxBUA0UX
SVVEUJBUUXRjBkEDRVeRVEVWkehqDIIGiu4i6TKK7sYgaKDoMpKuouhyDA5AoOiyIOmi6LIE
zgAEii4Lki6KLkvgDECg6DKSrqLocgwOQKDoLpIuo+huDA5AoOgqkqrIKhJdjcEBgEDRRVIV
ERQkVRTdmMEBgEBRRVJF0UVSRVGNGRwACBRdIkLRVSIkFN2YQVANFF3aYV2BCEU3ZnAQdANF
l9sFxcwMgm6g6HK7oJgZBF0NFF3uxpgZBF2OQNHlFoyYmUHQZRgMFF3mwFFF0OUdDEXR1QgM
HFUEXW7AGQxdxdFF0OVmHF1mBF1uVzS6iqDL7Q8jQAkAOw==
EOF
$image{error} = $mw->Photo(-data=>$data{error}, -format=>"gif");
...
# then, for example,...
my $dialog = $mw->Dialog(
-title => $PROGRAM,
-image => $image{error},
-text => $text,
-font => "Arial 8",
-buttons => [@buttons],
-default_button => $buttons[0],
);


Cary Millsap

=====encode.pl=====
use strict;
use warnings;
use Tk;
use Tk::Photo;
my $file = $ARGV[0];
my $w = MainWindow->new;
my $photo = $w->Photo(-file=>$file, -format=>"gif");
print $photo->data(-format=>"gif");

"Chris" <qab...@prodigy.net> wrote in message

news:P6y88.22396$_u.341...@newssvr16.news.prodigy.com...

0 new messages