我正在尝试用一个列表框填充python:
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)
但我遇到了以下错误: AttributeError:'ListBoxFrame'对象没有属性“listBox1” 你能告诉我我做错了什么吗?在
谢谢
您的
__init__
中的这一行:应该是:
^{pr2}$Python中的所有实例访问都通过
self.
工作。在相关问题 更多 >
编程相关推荐