I am trying to populate a list box from a list in python using this code:
import wx
class ListBoxFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'List Box Example', size=(500, 500))
panel = wx.Panel(self, -1)
btn1 = wx.Button(self, 1, 'List Items', (300, 130))
btn1.Bind(wx.EVT_BUTTON, self.ListItems)
listBox1 = wx.ListBox(choices=[], name='listBox1', parent=self, pos=wx.Point(8, 48), size=wx.Size(184, 256), style=0)
def ListItems(self, event):
sampleList = ['zero', 'one', 'two', 'three', 'four', 'five','six', 'seven', 'eight', 'nine', 'ten', 'eleven','twelve', 'thirteen', 'fourteen']
for item in sampleList:
self.listBox1.Insert(0,item)
But I am encountering with following error:
AttributeError: ‘ListBoxFrame’ object has no attribute ‘listBox1’
Can you please let me know what i am doing wrong?
Thanks
This line in your
__init__:should be:
All instance access in Python work through
self..