I wanted to insert an icon in my GUI. I have already tried inserting one but I need help and want to make it transparent. Can I make the icon transparent in any way? Any help would be appreciated.
Asked
Active
Viewed 1,251 times
2 Answers
1
I've voted to close this question as a duplicate; in the meantime, here is working code for what the first answer was trying to do:
Python 2.x:
from __future__ import with_statement
import Tkinter
import tempfile
import base64
import zlib
ICON = zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy'
'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc='))
_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
icon_file.write(ICON)
tk = Tkinter.Tk()
tk.iconbitmap(default=ICON_PATH)
label = Tkinter.Label(tk, text="Window with transparent icon.")
label.pack()
tk.mainloop()
Python 3.x:
import tkinter
import tempfile
import base64
import zlib
ICON = zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy'
'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc='))
_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
icon_file.write(ICON)
tk = tkinter.Tk()
tk.iconbitmap(default=ICON_PATH)
label = tkinter.Label(tk, text="Window with transparent icon.")
label.pack()
tk.mainloop()

maccartm
- 2,035
- 14
- 23
0
If you are using tkinter, you can use Python 3: tkinter.iconbitmap(yourIconFilePath)
Python 2: Tkinter.iconbitmap(yourIconFilePath)
NOTE: Icon files have the *.ico extension

dccsillag
- 919
- 4
- 14
- 25