【问题标题】:Can I create a wxPython tray icon application without the Python icon appearing in the Dock?我可以在 Dock 中不出现 Python 图标的情况下创建 wxPython 托盘图标应用程序吗?
【发布时间】:2012-10-15 16:30:13
【问题描述】:

这是我在 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()

它成功显示了一个托盘图标,确实没有显示任何框架,但它确实在 Dock 中显示了 Python 图标。我假设它还会在 Windows 任务栏中显示一个 Python 图标。我该如何阻止这种情况发生?

我在 OSX Mountain Lion 上的 Python 2.7 上使用 wxPython 2.9


【问题讨论】:

    标签: python macos wxpython system-tray


    【解决方案1】:

    您应该从您的应用程序创建一个捆绑包,并指定您的应用程序是一种“背景”,因此它不应在停靠栏中显示图标。

    为此,您必须将属性跟踪到您的捆绑属性文件 (Info.plist)。

    <key>LSUIElement</key>
    <string>1</string>
    

    参见以下文章:

    【讨论】:

      猜你喜欢
      • 2016-03-14
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 2012-01-05
      • 2012-10-27
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多