Python S1E5 wxPython wxListBox FillGet Selected Items
>> YOUR LINK HERE: ___ http://youtube.com/watch?v=9HT3rhDELgs
This is a wxPython ListBox tutorial and example.We also see how to handle selection events after populating it from a python list. • This is part of our wxPython series. As a wxPython widget, wxListBox allows us render lists of items in an easy manner. • SOURCE CODE REFERENCE : http://camposha.info/wxpython/listbox • Let's go. • What's up guys how do you do? Welcome to todays • edition of ProgrammingWizards TV. • In this tutorial we will look at wxPython ListBox. • First we populate the wxPython ListBox control • with data from a python list. • Then get the selected wxListBox item and show in • a messagebox. • We will be listening to wxPython ListBox • selection events and • getting the selected item. • wxPython allows us create consistent and native • user interfaces in python. • It's a cross platform GUI toolkit and is very • powerful. • First foremost create a python file. Am using • PyCharm IDE. • Then we import the wx package. • Then we come and create our class MyApp. • In this case our python class is deriving from • wx.App. • We are implementing the OnInit function which is • defined in • the wx.App class. • As you can see its taking a self which refers to • the current object. • We instantiate the a MrFrame, a custom class we • will be creating that inherits from wx.Frame. • We will assign that MrFrame instance as a • property of the self. • Then invoke the SetTopWindows() method, passing • in our frame. • Then invoke the show() function which will show • our • Frame. Then we come create our MrFrame class. • As you can see its deriving from wx.Frame. • So we override the special __ini__() function, • passing in the self • and parent. Then we invoke the _init_ function • of the wx.Frame, overriding it with default • parameters. These include the title of our • wx.Frame. • You can also see that we've passed the id as well • as the position. • Also we defined the size of the wx.Frame as well • as its style. • We come and invoke the SetSizeHintsSz, passing in • default sizes. • We also set the BackgroundColour of the frame. • We instantiate the FlexGridSizer. • Normally a FlexGridSizer lays out its children in • a two- dimensional table with all table fields in • one row having the same height. • We then instantiate a wx.BoxSizer allows us • arrange controls in a row or column. • In this case we will arrange items vertically in • our wx.BoxSizer layout. • Then we come instantiate our wx.StaticText, • passing in properties • like text, pount and defaultsize. • Then we set the font of the wx.StaticText. We • also add the wx.StaticText to our wxBoxGridSizer • object. • Then create a python list data structure to hold • our list of data. • This python list will be bound to our wxListBox. • Then we come instantiate our wxListBox, passing • in the id, point as well as the data source. • In this case the data source is our python list. • We are filling our wxListBox with python list. • We then set the font for ListBox. • Then add the wxListBox to our wxBoxGrdSizer. • Then add the wxBoxGridSizer to our • wxFlexGridSizer. • Then set our layout as the wxFlexGridSizer. • Remember all those we have done inside the • _ini_ fuction. • • Still inside the _init_ function we come and • listen to the wx.EVT_LISTBOX and register the • event handler. • • The event in this case is the wx.EVT_LISTBOX • while the event handler is the showSelectedItem. • • We are using the Bind() function to bind them. • Then we come and create our event handler. • This will listen to selection events of our • wxListBox and • show the selected item in a wxMessageBox. • You can see how we get the wxListBox selected • items using the • GetEventObject().GetStringSelection() invocation. • This will mean the item the user selects in the • wxListBox will be • displayed in our wxMessageBox. • Finally we come and check if we are in the main • module of • our application and instantiate our MyApp class. • Then invoke the MainLoop() method to run the • project. • • If we run the project you can see we have our • nice wxPython ListBox. • The items are bound from a python list. • Clicking an item shows it in a message box. • So that's it guys, our wxPython ListBox Selection • example and tutorial. The source code is in our • website http://camposha.info. • Please like the video,share it and subscribe. • Otherwise take care until next class.
#############################
