wxpython 最小化到托盘与欢迎图片的实现方法
一直在学习系统托盘的实现,于是自己写了一个简单的系统托盘实例,右键包括演示、最大化、最小化、退出和关于。在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()

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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.

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

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

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

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

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

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
