This example describes the use of a listbox in Wxpython. Share to everyone for your reference. Specific as follows:
# Load a listbox with names, select a name and display in title# experiments with WxPython by Vegaseat 20mar2005# Python V 2.4 and WxPython v2.5# If you had not already do so, install Python 2.4 first.# I used Python-2.4.1c2.msi 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.msiimport wxdef Create (Pare NT): 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, 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, 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, SIZE=WX). Size (184, style=0) Self.listBox1.SetBackgroundColour (WX. Colour (255, 255,)) 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 (approx.), style=0) Self.button2.Bind (WX. Evt_button, self. Onbutton2button, Id=wxid_frame1button2) def __init__ (self, parent): Self._init_ctrls (parent) def Onbutton1butto N (Self, Event): ' ' CLick button to load the listbox with names ' Self.listBox1.Append ("Andreas") self.listBox1.Append ("Erich") s Elf.listBox1.Append ("Udo") self.listBox1.Append ("Jens") self.listBox1.Append ("Bjorn") self.listBox1.Append ("Heidr Un ") 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 Stri Ng in Frame's title ' Selname = Self.listBox1.GetStringSelection () self. Settitle (Selname) def Onbutton2button (Self, event): "Click button to clear the ListBox items ' Self.list Box1.clear () #---------------End of Class Frame1--------------------# Program Entry point ... if __name__ = = ' __main__ ': App = WX. Pysimpleapp () wx. Initallimagehandlers () frame = Create (None) frame. Show () app. Mainloop ()
Hopefully this article will help you with Python programming.