简体   繁体   English

如何在基于Tkinter的Python GUI应用程序中替换Python徽标?

[英]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? 有没有办法更改窗口任务栏中显示的默认徽标,即Python徽标

Notice that I have already successfully replaced the default Tk logo that used to appear in my application window. 请注意,我已经成功替换了以前在我的应用程序窗口中显示的默认Tk徽标。

I am using Windows 7 and Python 2.6 and developing the GUI with the help of Tkinter. 我正在使用Windows 7和Python 2.6并在Tkinter的帮助下开发GUI。

You can do this using the winico Tk extension package. 您可以使用winico Tk扩展包执行此操作。 The winico package can also be used to add system tray icons to Tk programs. winico包还可用于向Tk程序添加系统托盘图标。

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. 请注意,您需要在命令行中提供具有合适大小的图标的.ico文件,并且您需要使用pythonw。 It will not change the taskbar icon for the console when it is running python script. 它在运行python脚本时不会更改控制台的任务栏图标。 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 . 为了测试这个,我将winico0.6包解压缩到我的python\\tcl\\winico0.6文件夹中,因此包需要Winico才能工作,然后使用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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM