Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace the Python logo in a Tkinter-based Python GUI app?

Is there a way to change the default logo, which is the Python logo, that appears in the Window's task bar?

Notice that I have already successfully replaced the default Tk logo that used to appear in my application window.

I am using Windows 7 and Python 2.6 and developing the GUI with the help of Tkinter.

like image 387
zml Avatar asked Feb 09 '26 17:02

zml


1 Answers

You can do this using the winico Tk extension package. The winico package can also be used to add system tray icons to Tk programs.

The following sample shows one way to do change the runtime application icon. Note that you need to provide a .ico file with suitable sizes of icons in it on the command line and you need to use pythonw. It will not change the taskbar icon for the console when it is running python script. To test this I extracted the winico0.6 package into my python\tcl\winico0.6 folder so the package require Winico would work and then ran the code below using pythonw winico_test.py path\to\some\ico\file.ico.

import sys
from Tkinter import *

def main(argv):
    root = Tk()
    root.update()
    root.tk.call('package','require','Winico')
    id = root.tk.call('winico','createfrom',argv[1])
    root.tk.call('winico','setwindow',root,id,'big',0)
    root.mainloop()
    return 0

if __name__=='__main__':
    sys.exit(main(sys.argv))
like image 174
patthoyts Avatar answered Feb 12 '26 06:02

patthoyts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!