简体   繁体   中英

Wxpython Application icon

I use wxpython and I try to add an icon to my application (Windows 10). However, The icon isn't shown in the taskbar only at the left side of the application. I use wxpython 4.0.7post. Someone knows why it doesn't work? This is my code: 这是wxpython的包 这是图标的显示方式

import wx
"""The icon's type is icon.ico"""
app = wx.App()
frame = wx.Frame(None, -1, title='2', pos=(0, 0), size=(200, 200))
frame.Show(True)
frame.SetIcon(wx.Icon(ICON_PATH, wx.BITMAP_TYPE_ICO))
app.SetTopWindow(frame)
app.MainLoop()

I found this solution - wxpython icon for task bar :

import ctypes
my_app_id = r'mycompany.myproduct.subproduct.version'  # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_app_id)

It works. Do you know what does it do?

The problem is, when you use wx.Frame.SetIcon , it set's the frame icon on the window bar. The icon in the task bar is the icon of the executable running the script. That means when you run straight from source code, the icon will be the python interpreter's icon. You'll need to set the icon using the win32 API if you want to have an icon while running from source, but if you distribute with a tool like PyInstaller, you can use the --icon option to add an icon the exe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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