Home Backend Development Python Tutorial wxpython 最小化到托盘与欢迎图片的实现方法

wxpython 最小化到托盘与欢迎图片的实现方法

Jun 16, 2016 am 08:43 AM
wxpython tray minimize

一直在学习系统托盘的实现,于是自己写了一个简单的系统托盘实例,右键包括演示、最大化、最小化、退出和关于。在python2.6下测试通过。

注意,本节分享的python实例代码,这里是托盘上的图标弹出菜单是覆盖了CreatePopupMenu。

也可以绑定2个方法,一个wx.EVT_TASKBAR_RIGHT_DOWN,方法里面生成menu,然后再来一个wx.EVT_MENU,定义要处理的事件函数。

还有一个就是Wx窗体上的最小化按钮,触发的事件是 wx.EVT_ICONIZE,而根本就没有定义什么wx.EVT_MINIMIZE,但是最大化,有个wx.EVT_MAXIMIZE。

复制代码 代码如下:

#!/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) # 最小化事件绑定 
    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()
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do I get the system tray icon to appear on all my Windows 11 monitors? How do I get the system tray icon to appear on all my Windows 11 monitors? Sep 22, 2023 pm 03:21 PM

When using a multi-monitor setup, users want to display the tray icon on all monitors in order to keep up with the latest notifications or access certain applications. This can be very useful, and in today's guide we'll show you how to enable this feature correctly. How to show tray icon on all monitors in Windows 11? 1. Use the display fusion software to visit the DisplayFusion website and download the software. After downloading the software, run the setup file and install it. Start the software and configure it as needed. On the second screen, right-click the taskbar, select Multi-monitor Taskbar, and then select System Tray. Finally, check Show/Hide Icons. Once this is done, you should get your system on both monitors on Windows 11

Python GUI programming: Get started quickly and easily create interactive interfaces Python GUI programming: Get started quickly and easily create interactive interfaces Feb 19, 2024 pm 01:24 PM

A brief introduction to python GUI programming GUI (Graphical User Interface, graphical user interface) is a way that allows users to interact with computers graphically. GUI programming refers to the use of programming languages ​​to create graphical user interfaces. Python is a popular programming language that provides a rich GUI library, making Python GUI programming very simple. Introduction to Python GUI library There are many GUI libraries in Python, the most commonly used of which are: Tkinter: Tkinter is the GUI library that comes with the Python standard library. It is simple and easy to use, but has limited functions. PyQt: PyQt is a cross-platform GUI library with powerful functions.

Python GUI Programming: Make your programs stand out Python GUI Programming: Make your programs stand out Feb 19, 2024 pm 08:33 PM

Introduction to pythonGUI programming PythonGUI programming, that is, graphical user interface programming, is the process of creating application program interfaces using the Python language. GUI applications usually have elements such as windows, buttons, text boxes, menus, etc., through which users can interact with the program. Python GUI programming has many benefits. First, it can make your program more beautiful and easier to use. Secondly, it can make your program cross-platform, that is, it can run on different operating systems. Third, it can make your program more flexible and easier to extend. Commonly used Python GUI libraries In Python, there are many commonly used GUI libraries, including Tkinter, PyQt, wxPython and PyG

Detailed explanation of the GUI library wxPython in Python Detailed explanation of the GUI library wxPython in Python Jun 09, 2023 pm 10:00 PM

Python is a concise, easy to learn, and efficient programming language. It is widely used in various fields such as data science, artificial intelligence, game development, network programming, etc. Although Python comes with some GUI libraries, their functions are relatively simple and cannot meet the needs of various complex applications. Therefore, there are many GUI libraries to choose from in Python, among which wxPython is one of them, which this article will introduce in detail. Introduction to wxPython wxPython is an open source, cross-platform GUI library based on

The Art of Python GUI Programming: Creating Beautiful and Easy-to-Use Interfaces The Art of Python GUI Programming: Creating Beautiful and Easy-to-Use Interfaces Feb 19, 2024 pm 05:36 PM

PythonGUI programming, as the name suggests, is a programming technology that uses the Python language to create a graphical user interface (GUI). Python GUI programming has many advantages, such as: cross-platform, rich third-party library support, concise syntax, etc. Therefore, Python GUI programming is deeply loved by programmers and is widely used in various types of application development. In Python GUI programming, the most commonly used third-party libraries are Tkinter, PyQt and wxPython. Tkinter is part of the Python standard library and is simple and easy to use, but has limited functionality. PyQt and wxPython are both powerful third-party GUI libraries, but they are also more

What are the options for GUI libraries in Python? What are the options for GUI libraries in Python? Oct 27, 2023 pm 03:10 PM

Python is an easy-to-learn, powerful programming language suitable for development in various fields. In Python, there are a variety of graphical user interface (GUI) libraries available that help developers create interactive desktop applications. This article will introduce some commonly used Python GUI libraries and provide specific code examples. Tkinter: Tkinter is Python's standard GUI library that provides functionality for creating simple window applications. Using Tkinter, we can easily

Python GUI programming: from beginner to proficient Python GUI programming: from beginner to proficient Feb 20, 2024 am 10:50 AM

1. Basics of pythonGUI programming PythonGUI programming refers to the process of creating a graphical user interface (GUI) using the Python language. GUI is the interface for users to interact with applications, usually consisting of windows, buttons, text boxes, list boxes and other controls. Python provides a variety of GUI libraries, such as Tkinter, PyQt, wxPython, etc. These libraries provide rich controls and event handling mechanisms, allowing Python programmers to easily create beautiful and practical GUI applications. 2. Getting Started with PythonGUI Programming Installing the PythonGUI Library Before starting GUI programming, you need to install the PythonGUI library first. Taking Tkinter as an example, you can

Uncover the magical world of Python GUI programming Uncover the magical world of Python GUI programming Feb 20, 2024 am 10:30 AM

Introduction to pythonGUI Programming PythonGUI programming is the process of creating a graphical user interface. Graphical user interface (GUI) is the interface for interaction between the user and the computer. It is an essential component of all modern computer systems. Python GUI programming provides an easy way to create applications with intuitive user interfaces. Getting started with PythonGUI programming Getting started with PythonGUI programming is very simple. You only need to install a GUI library such as Tkinter, PyQt or wxPython. These libraries provide easy ways to create GUIs. Tkinter is Python's own GUI library. It's very simple and easy to use, but has limited functionality. PyQt is a more powerful

See all articles