python: 系统托盘程序

# 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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值