Implementation of wxpython to minimize pallets and welcome Images

Source: Internet
Author: User

I have been learning the implementation of the system tray, so I wrote a simple system tray instance, right-click the instance, including demo, maximize, minimize, exit, and about. The test passed in python2.6.

Note: The python instance code shared in this section is that the icon pop-up menu on the tray overwrites CreatePopupMenu.

You can also bind two methods, one wx. EVT_TASKBAR_RIGHT_DOWN, generate a menu in the method, and then one wx. EVT_MENU to define the event function to be processed.

There is also the minimization button on the Wx form. The event triggered is wx. EVT_ICONIZE, and there is no definition of wx. EVT_MINIMIZE at all, but to maximize, there is a wx. EVT_MAXIMIZE.

Copy codeThe Code is 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! ', 'Propt ')

# 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 framework', 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! ', 'Propt ')
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.