Python GUI Creating ListBox in wxPython

In this Python GUI article i want to show Creating ListBox in wxPython. so this will be a simple project that a user can add, delete and edit a ListBox.

a listbox is used to select one or more of a list of strings. so The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video. a listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections).

 

 

This class supports the following styles:

  • wx.LB_SINGLE:  So it is a Single-selection list.
  • wx.LB_MULTIPLE: Multiple-selection list: the user can toggle multiple items on and off. This is the same as wx.LB_EXTENDED in wxGTK2 port.
  • wx.LB_EXTENDED: Extended-selection list: the user can extend the selection by using SHIFT or CTRL keys together with the cursor movement keys or the mouse.
  • wx.LB_HSCROLL: Create horizontal scrollbar if contents are too wide (Windows only).
  • wx.LB_ALWAYS_SB: Always show a vertical scrollbar.
  • wx.LB_NEEDED_SB: Only create a vertical scrollbar if needed.
  • wx.LB_NO_SB: Don’t create vertical scrollbar (wxMSW and wxGTK only).
  • wx.LB_SORT: The listbox contents are sorted in alphabetical order.

 

 

 

 

Also you can check More GUI Development Tutorials in the below link.

1: PyQt5 GUI Development Tutorials

2: TKinter GUI Development Tutorials

3: Pyside2 GUI Development Tutorials 

4: Kivy GUI Development Tutorials

 

 

 

 

So this is the complete code for Python GUI Creating ListBox in wxPython

 

 

 

 

This is class is MyFrame class that inherits from wx.Frame and it is our top level window that we create our MyPanel object in this class

 

 

 

 

 

This is our MyPanel class and we create our all widgets, layouts and bindings in this class

 

 

 

 

And this is the the creation of our HBox Sizer and ListBox

 

 

 

 

It is time to create our btnPanel because we are going to add some buttons in this panel

 

 

 

 

These are event bindings for our buttons

 

 

 

 

 

So these are the methods that we have used for binding

 

 

 

 

 

So the last class is MyApp class that inherits from wx.App. the OnInit() method is where you will most often create frame subclass objects. and start our main loop.That’s it. Once the application’s main event loop processing takes over, control passes to wxPython. Unlike procedural programs, a wxPython GUI program primarily responds to the events taking place around it, mostly determined by a human user clicking with a mouse and typing at the keyboard. when all the frames in an application have been closed, the app.MainLoop() method will return and the program will exit.

 

 

 

 

 

So run the code and this will be the result

Python GUI Creating ListBox in wxPython
Python GUI Creating ListBox in wxPython

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×