按下按钮时更改列表中的数据

changing data in list on button press

在 wxpython 中,当用户按下按钮时如何更新列表中的信息...我的代码是这样的:

ButtonImage8 = "Images/GUI/MP3Player/button_reload.bmp"
ButtonImageBMP8 = wx.Image(ButtonImage8, wx.BITMAP_TYPE_ANY).ConvertToBitmap()

button8 = wx.BitmapButton(BUTTONpanel8, id=wx.ID_ANY,bitmap=ButtonImageBMP8, size=(40, 40), pos=(0, 0),style=wx.NO_BORDER)
button8.Bind(wx.EVT_BUTTON, self.Music_Reload)


BUTTONpanel8 = wx.Panel(self, -1, pos=(280, 160), size=(40, 40), style=wx.NO_BORDER)

MP3FileListPanel = wx.Panel(self, -1,style=wx.NO_BORDER, pos=(0, 0), size=(320, 160))

MP3FileList = wx.ListBox(choices=[], parent=MP3FileListPanel, pos=wx.Point(0, 0),size=(320, 160))

def Music_Reload(自我, 事件): 对于 os.walk("/home/tjohnson/python") 中的根、目录、文件: 对于文件中的文件: 如果 file.endswith(".py"): self.MP3FileList.Append(文件) 打印(os.path.join(根目录,文件))

当我按下按钮时,代码显示 "Attribute not found" 指的是列表框,请记住我已经从完整脚本中提取了这段代码。当它尝试 self.list.append() 时会抛出错误

您可以使用 SetItemswx.ListBox 小部件中设置整个选项列表。我没有在您的代码片段中看到 self.list 定义,所以我不确定它指的是什么。