wxPython中listbox用法实例详解
本文实例讲述了wxPython中listbox用法。分享给大家供大家参考。具体如下:
# load a listbox with names, select a name and display in title # experiments with wxPython by vegaseat 20mar2005 # Python v2.4 and wxPython v2.5 # If you have not already done so, install Python 2.4 first. # I used python-2.4.1c2.msi (this is the self-extracting # MS-Installer file) from http://www.python.org # Then install wxPython2.5-win32-unicode-2.5.4.1-py24.exe # from: http://prdownloads.sourceforge.net/wxpython/ # (if you don't get into unicode, download the ansi version) # note: python-2.4.1c2.msi should soon be python-2.4.1.msi import wx def create(parent): return Frame1(parent) # assign ID numbers [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1LISTBOX1, ] = [wx.NewId() for _init_ctrls in range(4)] class Frame1(wx.Frame): def _init_ctrls(self, prnt): # BOA generated methods wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(358, 184), size=wx.Size(299, 387), style=wx.DEFAULT_FRAME_STYLE, title=u'ListBox Test ...') self.SetClientSize(wx.Size(291, 347)) self.SetBackgroundColour(wx.Colour(0, 128, 0)) self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'Load ListBox', name='button1', parent=self, pos=wx.Point(8, 8), size=wx.Size(176, 28), style=0) self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, id=wxID_FRAME1BUTTON1) self.listBox1 = wx.ListBox(choices=[], id=wxID_FRAME1LISTBOX1, name='listBox1', parent=self, pos=wx.Point(8, 48), size=wx.Size(184, 256), style=0) self.listBox1.SetBackgroundColour(wx.Colour(255, 255, 128)) self.listBox1.Bind(wx.EVT_LISTBOX, self.OnListBox1Listbox, id=wxID_FRAME1LISTBOX1) self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label=u'Clear', name='button2', parent=self, pos=wx.Point(104, 312), size=wx.Size(87, 28), style=0) self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button, id=wxID_FRAME1BUTTON2) def __init__(self, parent): self._init_ctrls(parent) def OnButton1Button(self, event): ''' click button to load the listbox with names ''' self.listBox1.Append("Andreas") self.listBox1.Append("Erich") self.listBox1.Append("Udo") self.listBox1.Append("Jens") self.listBox1.Append("Bjorn") self.listBox1.Append("Heidrun") self.listBox1.Append("Ulla") self.listBox1.Append("Volger") self.listBox1.Append("Helmut") self.listBox1.Append("Freja") self.SetTitle("Select a name ...") def OnListBox1Listbox(self, event): ''' click list item and display the selected string in frame's title ''' selName = self.listBox1.GetStringSelection() self.SetTitle(selName) def OnButton2Button(self, event): ''' click button to clear the listbox items ''' self.listBox1.Clear() #--------------- end of class Frame1 -------------------- # program entry point ... if __name__ == '__main__': app = wx.PySimpleApp() wx.InitAllImageHandlers() frame = create(None) frame.Show() app.MainLoop()
希望本文所述对大家的Python程序设计有所帮助。

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

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 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

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 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

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

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

1. Introduction 2. Text The application scenarios of CAPTCHA are mainly in scenarios where user identity needs to be verified or malicious attacks need to be prevented. Here are several common application scenarios: User login verification: CAPTCHA is used when users log in to prevent automated robots from logging into their accounts. . Website registration verification: Use CAPTCHA to prevent automated bots from registering accounts. Web crawler restrictions: Some websites may restrict crawler access. Using CAPTCHA can prevent malicious crawler attacks. Email spam filtering: Use CAPTCHA to prevent automated robots from sending spam. Online surveys: Use CAPTCHA to ensure the accuracy and trustworthiness of online survey results. Website Review: Use CAPTCHA to Prevent Automation
