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

烂漫一生 提交于 2019-12-10 09:56:50

问题


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.


回答1:


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))


来源:https://stackoverflow.com/questions/22618156/how-to-replace-the-python-logo-in-a-tkinter-based-python-gui-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!