如何在基于 Tkinter 的 Python GUI 应用程序中替换 Python 徽标? [英] How to replace the Python logo in a Tkinter-based Python GUI app?

查看:19
本文介绍了如何在基于 Tkinter 的 Python GUI 应用程序中替换 Python 徽标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法更改默认标志,即 Python 标志,出现在窗口的任务栏中?

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

请注意,我已经成功替换了曾经出现在我的应用程序窗口中的默认 Tk 徽标.

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

我正在使用 Windows 7 和 Python 2.6,并在 Tkinter 的帮助下开发 GUI.

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

推荐答案

您可以使用 winico Tk 扩展包.winico 包也可用于向 Tk 程序添加系统托盘图标.

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.

以下示例展示了一种更改运行时应用程序图标的方法.请注意,您需要在命令行上提供一个带有合适大小图标的 .ico 文件,并且您需要使用 pythonw.它不会在运行 python 脚本时更改控制台的任务栏图标.为了测试这一点,我将 winico0.6 包解压到我的 python\tcl\winico0.6 文件夹中,以便 package require Winico 可以工作,然后使用 pythonw winico_test.py path\to\some\ico\file.ico.

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

这篇关于如何在基于 Tkinter 的 Python GUI 应用程序中替换 Python 徽标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆