has been learning the implementation of the system tray, so I wrote a simple system tray instance, the right key includes demo, Maximize, Minimize, exit and about. The test passed under python2.6.
Note that this section shares the Python instance code, where the icon pop-up menu on the tray is covered with createpopupmenu.
You can also bind 2 methods, one WX. Evt_taskbar_right_down, the method inside generates menu, then another wx. Evt_menu, defines the event functions to be processed.
Another is the Minimize button on the Wx form, and the event that triggers is WX. Evt_iconize, and there is nothing at all to define WX. Evt_minimize, but maximized, there is a wx. Evt_maximize.
Copy Code code as follows:
#!/usr/bin/python
# _*_ Coding:utf-8 _*_
Import WX
Class Taskbaricon (WX. Taskbaricon):
Id_hello = wx. NewId ()
def __init__ (self, frame):
Wx. Taskbaricon.__init__ (self)
Self.frame = Frame
Self. SetIcon (WX. Icon (name= ' Wx.ico ', type=wx. Bitmap_type_ico), ' taskbaricon! ')
Self. Bind (WX. Evt_taskbar_left_dclick, self. Ontaskbarleftdclick)
Self. Bind (WX. Evt_menu, self. OnHello, Id=self.id_hello)
def ontaskbarleftdclick (self, event):
If Self.frame.IsIconized ():
Self.frame.Iconize (False)
If not Self.frame.IsShown ():
Self.frame.Show (True)
Self.frame.Raise ()
def onhello (self, event):
Wx. MessageBox (' Hello from taskbaricon! ', ' Prompt ')
# Override
def createpopupmenu (self):
menu = WX. Menu ()
Menu. Append (Self.id_hello, ' Hello ')
Return menu
Class Frame (WX. Frame):
Def __init__ (
Self, parent=none, Id=wx.id_any, title= ' Taskbaricon ', pos=wx. Defaultposition,
Size=wx. DefaultSize, Style=wx. Default_frame_style
):
Wx. Frame.__init__ (self, parent, ID, title, pos, size, style)
# Create a Welcome screen
Screen = WX. Image (Self.screenim). Converttobitmap ()
Wx. SplashScreen (screen, WX.) Splash_centre_on_screen | Wx. splash_timeout,1000, None,-1)
Wx. Yield ()
Self. SetIcon (WX. Icon (' Wx.ico ', WX. Bitmap_type_ico))
panel = WX. Panel (self, wx.id_any)
button = WX. Button (panel, Wx.id_any, ' Hide Frame ', pos= (60, 60))
Sizer = WX. Boxsizer ()
Sizer. ADD (button, 0)
Panel. Setsizer (Sizer)
Self.taskbaricon = Taskbaricon (self)
# bind Event
Self. Bind (WX. Evt_button, self. Onhide, Button)
Self. Bind (WX. Evt_close, self. OnClose)
Self. Bind (WX. Evt_iconize, self. oniconfiy) # Minimize Event Binding
def onhide (self, event):
Self. Hide ()
def oniconfiy (self, event):
Wx. MessageBox (' Frame has been iconized! ', ' Prompt ')
Event. Skip ()
def OnClose (self, event):
Self.taskBarIcon.Destroy ()
Self. Destroy ()
Def testframe ():
App = WX. Pysimpleapp ()
frame = FRAME (size= (640, 480))
Frame. Centre ()
Frame. Show ()
App. Mainloop ()
if __name__ = = ' __main__ ':
Testframe ()