[Tkinter-discuss] Application window icon on Linux
Mark Summerfield
list at qtrac.plus.com
Thu Jun 7 18:18:25 CEST 2012
Hi,
I am struggling to get an application icon to show up on Linux.
(Although it works perfectly on Windows.)
I know this issue has come up before and I've followed the advice: I
made the icon 16x16, XBM format, and prefixed the full path with '@'.
I am using Python 3.2.2 and Tcl/Tk 8.5.
Here is a complete example:
#!/usr/bin/env python3
import os
from tkinter import *
from tkinter.ttk import *
class Window(Frame):
def __init__(self, parent):
super().__init__(parent)
quitButton = Button(self, text="Quit",
command=self.master.destroy)
quitButton.pack()
self.pack()
self.set_icon(os.path.join(os.getcwd(), "hello"))
# hello.xbm, hello.ico; both 16x16
def set_icon(self, iconName):
windowSystem = self.master.tk.call("tk", "windowingsystem")
if windowSystem == "win32": # Windows
iconName += ".ico"
elif windowSystem == "x11": # Unix
iconName = "@" + iconName + ".xbm"
if windowSystem != "aqua" and os.path.isfile(iconName):
print(iconName)
self.master.iconbitmap(iconName)
#self.master.wm_iconbitmap(iconName) also works
app = Tk()
app.title("Hello")
Window(app)
app.mainloop()
This works perfectly on Windows 7. But on Linux (Debian & Ubuntu), I
just get a default icon. The print() statement produces:
@/home/mark/hello.xbm
This hello.xbm file's contents are:
#define hello_width 16
#define hello_height 16
static unsigned char hello_bits[] = {
0x00, 0x00, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70,
0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70,
0x0e, 0x70, 0x0e, 0x70, 0x0e, 0x70, 0x00, 0x00 };
Thanks!
--
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
C++, Python, Qt, PyQt - training and consultancy
"Programming in Python 3" - ISBN 0321680561
http://www.qtrac.eu/py3book.html
More information about the Tkinter-discuss
mailing list