wxpython如何设置图标_任务栏的wxpython图标

I am trying to set an icon in my wxpython program. So far, after reading many pages and examples, I was able to set an icon at the window, which also works when using alt+tab (I'm working over Windows 7).

But the icon at task bar is the usual python default icon.

I don't understand why are there so many troubles for such a simple task.

Here is my code:

class GraphFrame(wx.Frame):

""" The main frame of the application

"""

title = 'My first wxprogram'

def __init__(self):

wx.Frame.__init__(self, None, -1, self.title)

ico = wx.Icon('dog.ico', wx.BITMAP_TYPE_ICO)

self.SetIcon(ico)

self.set_icon

self.create_menu()

self.create_status_bar()

self.create_main_panel()

#...

解决方案

It's currently not possible to set the taskbar icon via wxPython (Unless you hack apart the system variables), this is because windows gets the application icon from the executable (Which in your case is Python)

If you use either pyinstaller or py2exe (I prefer the former), when compiling it can set the applications icon - which will make the taskbar icon correct.

If using pyinstaller, you'll want to set the icon as such in the specfile:

exe = EXE(pyz,

a.scripts,

a.binaries,

a.datas,

name=os.path.join('..\\path\\to\\output', 'AppName.exe'),

icon='C:\\abs\\path\\to\\icon\\icon.ico',

debug=False,

strip=False,

upx=False,

console=False )

The icon=... line sets the taskbar icon.

The rest of your python code is fine as is.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值