I would like to be able to change the icon of a window displayed using
Ruby and Tk.
Using Perl and Tk I can do the following:
use strict;
use warnings;
use Tk;
my $mymainwindow = MainWindow->new();
my $myicon = $mymainwindow->Photo(-file=>“myimage.gif”);
$mymainwindow->iconimage($myicon);
MainLoop();
How would I go about doing this using Ruby and Tk?
I have tried the following:
require ‘tk’
mymainwindow = TkRoot.new()
myicon = TkPhotoImage.new {file “myimage.gif”}
mymainwindow.iconimage(myicon)
Tk.mainloop()
I get the error unknown option “-iconimage” at runtime.
What is the correct way to set the icon image for a window using Ruby
and Tk?
Does anyone know if it is even possible to change the window icon using
Ruby and Tk?
On Aug 21, 2006, at 9:18 PM, Dave Mihalik wrote:
Does anyone know if it is even possible to change the window icon
using
Ruby and Tk?
I’m replying only because nobody else seems willing to and not
because I have the answer you’re seeking. The short answer seems to
be: no, but it might be platform dependent. The semi-official RubyTk
documentation http://www.jbrowse.com/text/rubytk_en.html that I
consulted gives the following example:
Tk::Wm#iconbitmap(bitmap=None)
Sets the bitmap displayed in the icon to bitmap.
If nil is passed, the icon’s bitmap setting is erased. If the
argument is omitted, the current setting is returned.
require “tk”
Tk.root.iconify
p Tk.root.iconbitmap “question”
p Tk.root.iconbitmap
Tk.mainloop
=> “”
“question”
Perhaps this code can change the window icon on platforms running X-
Window/Motif, but I can’t say from experience.
Running it on my platform, OS X with Aqua, produces no visible
effect. But how could it? From OS X’s point of view the Ruby program
is a Unix command line session, and it displays the appropriate icon
for such a session in the dock. If I minimize a Tk window, I get a
bitmap thumbnail of the running window in the dock (again normal for
OS X).
On OS X, I could get a custom icon by making the Ruby program a
component of an application package (bundle) containing an icon
resource, an info.plist file, and a launcher script written in
AppleScript. On MS Windows, it’s probably all very different. I
wouldn’t have a clue on how get a custom program icon there.
Regards, Morton
Thanks for the help!
I am trying to change the icon using ruby and tk on Windows XP and
Windows Server 2003.
I tried:
require ‘tk’
mymainwindow = TkRoot.new()
mymainwindow.iconify
mymainwindow.iconbitmap “question”
Tk.mainloop()
and also
require ‘tk’
Tk.root.iconify
p Tk.root.iconbitmap “question”
Tk.mainloop()
Neither of these examples changes the icon.
Dave Mihalik wrote in post #128770:
Thanks for the help!
I am trying to change the icon using ruby and tk on Windows XP and
Windows Server 2003.
I tried:
require ‘tk’
mymainwindow = TkRoot.new()
mymainwindow.iconify
mymainwindow.iconbitmap “question”
Tk.mainloop()
and also
require ‘tk’
Tk.root.iconify
p Tk.root.iconbitmap “question”
Tk.mainloop()
Neither of these examples changes the icon.
Sorry for the late answer, but:
root = TkRoot.new
myicon = TkPhotoImage.new(‘file’ => ‘myicon.gif’)
root.iconphoto(myicon)
Only GIF, God knows, why.
Best regards:
Zoltan
From: Zoltn H. [email protected]
Subject: Re: How do I set the icon for a window using Ruby Tk?
Date: Sat, 04 Jan 2014 20:27:16 +0100
Message-ID: [email protected]
root = TkRoot.new
myicon = TkPhotoImage.new(‘file’ => ‘myicon.gif’)
root.iconphoto(myicon)
Only GIF, God knows, why.
Standard Tcl/Tk has image handlers for PPM, PGM and GIF.
(Please see Tcl/Tk’s “photo” comman manual.)
To support other image formats (e.g. JPEG), Img package is required.
When Img package is installed for your Tcl/Tk (which linked to Ruby/Tk),
you can use Img package by “require ‘tkextlib/tkimg’”.