Quick and easy: trayicon with python?

前端 未结 9 1905
一生所求
一生所求 2020-11-28 03:27

I\'d just need a quick example on how to easily put an icon with python on my systray. This means: I run the program, no window shows up, just a tray icon (I\'ve got a png f

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 03:54

    Yes. There is a cross-platform example on wiki.wxpython.org that I've tested with python 2.7 (minconda install) on macOS High Sierra (10.13.3), Windows 7, and gnome 3/centos7. It is here (ignore the page title): https://wiki.wxpython.org/Custom%20Mac%20OsX%20Dock%20Bar%20Icon

    Small mods are needed for python 3.6:

    • you must import wx.adv
    • wx.TaskBarIcon becomes wx.adv.TaskBarIcon
    • wx.IconFromBitmap becomes wx.Icon

    Gnome 3 required installation of TopIcons Plus.

    Since you don't want to have the window display (" no window shows up, just a tray icon"), simply comment out the following line (though you still want to keep the wx.Frame parent):

    frame.Show(True)
    

    And since you want to use your own .png icon, remove the WXPdemo image and embeddedimage stuff and replace

    icon = self.MakeIcon(WXPdemo.GetImage())
    

    with, for example

    icon = wx.Icon('icon.png')
    

    In my experience, this will provide a good start for adapting or extending further.

提交回复
热议问题