python在程序中没有找到图标,我可以创建一个wxPython托盘图标应用程序而不在Dock中显示Python图标吗?...

Here is the slightly modified source code for an example tray icon application I found on SO:

import wx

TRAY_TOOLTIP = 'System Tray Demo'

TRAY_ICON = 'icon.png'

def create_menu_item(menu, label, func):

item = wx.MenuItem(menu, -1, label)

menu.Bind(wx.EVT_MENU, func, id=item.GetId())

menu.AppendItem(item)

return item

class TaskBarIcon(wx.TaskBarIcon):

def __init__(self):

super(TaskBarIcon, self).__init__()

self.set_icon(TRAY_ICON)

self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)

def CreatePopupMenu(self):

menu = wx.Menu()

create_menu_item(menu, 'Say Hello', self.on_hello)

menu.AppendSeparator()

create_menu_item(menu, 'Exit', self.on_exit)

return menu

def set_icon(self, path):

icon = wx.IconFromBitmap(wx.Bitmap(path))

self.SetIcon(icon, TRAY_TOOLTIP)

def on_left_down(self, event):

print 'Tray icon was left-clicked.'

def on_hello(self, event):

print 'Hello, world!'

def on_exit(self, event):

wx.CallAfter(self.Destroy)

class App(wx.App):

def OnInit(self):

self.SetTopWindow(wx.Frame(None, -1))

TaskBarIcon()

return True

def main():

app = App()

app.MainLoop()

if __name__ == '__main__':

main()

It shows a tray icon successfully, and indeed shows no Frame, but it does show the Python icon in the Dock. I assume it will also show a Python icon in the Windows task bar. How do I stop that from happening?

I'm using wxPython 2.9 on Python 2.7 on OSX Mountain Lion

4g4Et.png

解决方案

You should create a bundle from Your application and tell specify that your app is kind of "background", so it shall not show icon in dock.

To do this, You have to following property to Your bundle property file (Info.plist).

LSUIElement

1

See following articles:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值