摘自:
http://wiki.wxpython.org/index.cgi/FlashingTaskbarIcon

完整代如下:
wxPython创建系统托盘#导入wxPython模块
wxPython创建系统托盘
from wxPython.wx import *
wxPython创建系统托盘
wxPython创建系统托盘ICON_STATE 
= 0
wxPython创建系统托盘BLINK_STATE 
= 0
wxPython创建系统托盘
wxPython创建系统托盘ID_ICON_TIMER 
= 1000
wxPython创建系统托盘
#创建继承wxFrame的类
wxPython创建系统托盘
class TaskBarApp(wxFrame):
wxPython创建系统托盘    
def __init__(self, parent, id, title):
wxPython创建系统托盘    
#构造一窗体
wxPython创建系统托盘
    wxFrame.__init__(self, parent, -1, title, size = (11),style=wxFRAME_NO_TASKBAR|wxNO_FULL_REPAINT_ON_RESIZE)
wxPython创建系统托盘        
wxPython创建系统托盘    
#创建系统托盘ICO对象并赋给tbicon
wxPython创建系统托盘
    self.tbicon = wxTaskBarIcon()
wxPython创建系统托盘        
wxPython创建系统托盘    icon 
= wxIcon('bb_yellow.ico', wxBITMAP_TYPE_ICO)
wxPython创建系统托盘
wxPython创建系统托盘    self.tbicon.SetIcon(icon, 
'')
wxPython创建系统托盘
wxPython创建系统托盘    
#绑定一些事件
wxPython创建系统托盘
    EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarLeftDClick)
wxPython创建系统托盘    EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarRightClick)
wxPython创建系统托盘    self.Show(true)
wxPython创建系统托盘
wxPython创建系统托盘    
#左键双击事件的处理方法
wxPython创建系统托盘
    def OnTaskBarLeftDClick(self, evt):
wxPython创建系统托盘        
global ICON_STATE
wxPython创建系统托盘        
try:
wxPython创建系统托盘            self.icontimer.Stop()
wxPython创建系统托盘        
except:
wxPython创建系统托盘            
pass
wxPython创建系统托盘        
if ICON_STATE == 1:
wxPython创建系统托盘            icon 
= wxIcon('bb_yellow.ico', wxBITMAP_TYPE_ICO)
wxPython创建系统托盘            self.tbicon.SetIcon(icon, 
'Yellow')
wxPython创建系统托盘            ICON_STATE 
= 0
wxPython创建系统托盘        
else:
wxPython创建系统托盘            self.SetIconTimer()
wxPython创建系统托盘            ICON_STATE 
= 1
wxPython创建系统托盘
wxPython创建系统托盘    
#右键单击处理方法
wxPython创建系统托盘
    def OnTaskBarRightClick(self, evt):
wxPython创建系统托盘        self.Close(true)
wxPython创建系统托盘        wxGetApp().ProcessIdle()
wxPython创建系统托盘
wxPython创建系统托盘    
def SetIconTimer(self):
wxPython创建系统托盘        self.icontimer 
= wxTimer(self, ID_ICON_TIMER)
wxPython创建系统托盘        EVT_TIMER(self, ID_ICON_TIMER, self.BlinkIcon)
wxPython创建系统托盘        self.icontimer.Start(
1000)
wxPython创建系统托盘
wxPython创建系统托盘    
def BlinkIcon(self, evt):
wxPython创建系统托盘        
global BLINK_STATE
wxPython创建系统托盘        
if BLINK_STATE == 0:
wxPython创建系统托盘            icon 
= wxIcon('bb_red.ico', wxBITMAP_TYPE_ICO)
wxPython创建系统托盘            self.tbicon.SetIcon(icon, 
'Red')
wxPython创建系统托盘            BLINK_STATE 
= 1
wxPython创建系统托盘        
else:
wxPython创建系统托盘            icon 
= wxIcon('bb_black.ico', wxBITMAP_TYPE_ICO)
wxPython创建系统托盘            self.tbicon.SetIcon(icon, 
'Black')
wxPython创建系统托盘            BLINK_STATE 
= 0
wxPython创建系统托盘
wxPython创建系统托盘
#创建App类
wxPython创建系统托盘
class MyApp(wxApp):
wxPython创建系统托盘    
def OnInit(self):
wxPython创建系统托盘        frame 
= TaskBarApp(None, -1' ')
wxPython创建系统托盘        frame.Center(wxBOTH)
wxPython创建系统托盘        frame.Show(false)
wxPython创建系统托盘        
return true
wxPython创建系统托盘
#run
wxPython创建系统托盘
def main():
wxPython创建系统托盘    app 
= MyApp(0)
wxPython创建系统托盘    app.MainLoop()
wxPython创建系统托盘
if __name__ == '__main__':
wxPython创建系统托盘    main()

根据自己的理解补了一些注释,希望能够看的清楚点...

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-12-06
  • 2022-02-09
  • 2021-12-23
  • 2021-12-24
猜你喜欢
  • 2022-01-08
  • 2022-12-23
  • 2021-08-16
  • 2021-09-07
  • 2022-12-23
  • 2021-07-29
相关资源
相似解决方案