WXPython:填充列表框的问题

2024-10-03 09:13:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用一个列表框填充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” 你能告诉我我做错了什么吗?在

谢谢


Tags: importselfsizeinitdefitemframelist