# coding=utf-8
import wx
import wx.adv
class MainFrame(wx.Frame):
def __init__(self, title, pos, size):
wx.Frame.__init__(self, None, -1, title, pos, size)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.SetIcon(wx.Icon('sr.ico'))
self.tbIco = TBIcon()
def OnClose(self, e):
self.Show(False)
return
class TBIcon(wx.adv.TaskBarIcon):
def __init__(self):
super().__init__()
self.ID_SHOW = 1000
self.ID_EXIT = 1001
self.SetIcon(wx.Icon("sr.ico"), "SR")
self.Bind(wx.EVT_MENU, self.onShow, id=self.ID_SHOW)
self.Bind(wx.EVT_MENU, self.onExit, id=self.ID_EXIT)
def CreatePopupMenu(self):
menu = wx.Menu()
menu.Append(self.ID_SHOW, '显示')
menu.Append(self.ID_EXIT, '退出')
return menu
def onShow(self, event):
window.Show()
return
def onExit(self, event):
self.RemoveIcon()
self.Destroy()
wx.Exit()
if __name__ == '__main__':
app = wx.App()
# window = wx.Frame(None, title="wxPython", size=(300, 200))
window = MainFrame('wxPython', (50, 60), (450, 340))
# panel = wx.Panel(window)
# label = wx.StaticText(panel, label="wxPython", pos=(100, 50))
window.Center()
window.Show(True)
app.MainLoop()
python: 系统托盘程序
最新推荐文章于 2024-04-19 09:57:09 发布