Tkinter, iconbitmap and Windows XP

Discussion in 'Python' started by John Fouhy, Jan 5, 2005.

  1. John Fouhy

    John Fouhy Guest

    Hi all,

    I have been attempting to change the title bar icon of my Tkinter
    applications in Windows XP. Chasing round in google, I discovered:
    - This is a common difficulty.
    - There aren't any good answers.

    Eventually, I stumbled across a link to this:
    http://www.tcl.tk/man/tcl8.4/TkCmd/wm.htm#M18

    Here is the significant information:
    "On the Windows operating system, an additional flag is supported: wm
    iconbitmap window ?-default? ?image?. If the -default flag is given,
    the icon is applied to all toplevel windows (existing and future) to
    which no other specific icon has yet been applied. In addition to
    bitmap image types, a full path specification to any file which
    contains a valid Windows icon is also accepted (usually .ico or .icr
    files), or any file for which the shell has assigned an icon. Tcl will
    first test if the file contains an icon, then if it has an assigned
    icon, and finally, if that fails, test for a bitmap."

    The Tkinter source (Python 2.3.4) includes this:

    def wm_iconbitmap(self, bitmap=None):
    """Set bitmap for the iconified widget to BITMAP. Return
    the bitmap if None is given."""
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)

    I modified this, to look like:

    def wm_iconbitmap(self, bitmap=None, default=None):
    """Set bitmap for the iconified widget to BITMAP. Return
    the bitmap if None is given."""
    if default:
    return self.tk.call('wm', 'iconbitmap', self._w,
    '-default', default)
    else:
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)

    The following code now does exactly what you would like it to:

    #####
    from Tkinter import *

    tk = Tk()
    tk.iconbitmap(default='foo.ico')
    Label(tk, text='This window now has a custom icon.').pack()

    t = Toplevel(tk)
    Label(t, text='This one has the same custom icon.').pack()

    tk.mainloop()
    #####

    I hope this is helpful to people...

    (now to see if I can figure out how to submit a patch in Sourceforge)

    --
    John.
     
    John Fouhy, Jan 5, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Epler
    Replies:
    0
    Views:
    510
    Jeff Epler
    Aug 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    459
    Jeff Epler
    Aug 23, 2004
  3. Pierre Dagenais
    Replies:
    0
    Views:
    321
    Pierre Dagenais
    Aug 3, 2008
  4. Hidekazu IWAKI
    Replies:
    1
    Views:
    384
    Peter Otten
    Dec 14, 2009
  5. Hidekazu IWAKI
    Replies:
    0
    Views:
    527
    Hidekazu IWAKI
    Dec 15, 2009
Loading...

Share This Page