【问题标题】:Error when im trying add a column to a ListCtrl in wxPython(4.0.6)我尝试在 wxPython(4.0.6) 中向 ListCtrl 添加列时出错
【发布时间】:2019-10-12 01:55:26
【问题描述】:

我正在尝试向 LisCtrl 添加一列,但我不能

我试图按照文档进行操作,但我不知道我做错了什么

文档说:InsertColumn (self, col, heading, format=LIST_FORMAT_LEFT, width=LIST_AUTOSIZE)

(https://docs.wxpython.org/wx.ListCtrl.html#wx.ListCtrl.InsertColumn)

导入 wx

类 View1(wx.Frame): def init(self,*args,**kw): super(View1, self).init(*args,**kw)

panel = wx.Panel(self, pos=(0,0), size=(800,700)) #TITULO titulo = wx.StaticText(panel,label="AGENDA DE CONTACTOS",pos=(130,1)) #Creamos Sizer y le agregamos el titulo sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(titulo,0,wx.ALIGN_CENTER,0) panel.SetSizer(sizer) #Texto1 X,Y label1 = wx.StaticText(panel,label="Nombre",pos=(70,50)) field1 = wx.TextCtrl(panel,pos=(200,50), size=(150,20)) #Texto2 X,Y label2 = wx.StaticText(panel,label="Apellido Paterno",pos=(70,90)) field2 = wx.TextCtrl(panel,pos=(200,90), size=(150,20)) #Texto3 X,Y label3 = wx.StaticText(panel,label="Apellido Materno",pos=(70,130)) field3 = wx.TextCtrl(panel,pos=(200,130), size=(150,20)) #Texto4 X,Y label4 = wx.StaticText(panel,label="Teléfono ",pos=(70,170)) field4 = wx.TextCtrl(panel,pos=(200,170), size=(150,20)) #Texto5 X,Y label5 = wx.StaticText(panel,label="Correo",pos=(70,210)) field5 = wx.TextCtrl(panel,pos=(200,210), size=(150,20)) #Texto6 X,Y label6 = wx.StaticText(panel,label="Teléfono",pos=(450,50)) field6 = wx.TextCtrl(panel,pos=(550,50), size=(150,21)) #Boton Agregar botonAgregar = wx.Button(panel,label="Agregar",pos=(215,245),size=(120,22)) #Boton eliminar botonEliminar = wx.Button(panel,label="Eliminar",pos=(565,90),size=(120,22)) #Creamos el ListCtrl para desplegar la información tabla = wx.ListCtrl(panel,pos=(25,350),size=(750,250), style=wx.LC_LIST) tabla.InsertColumn (self,0, 'NOMBRE', format=wx.LIST_FORMAT_LEFT, width=wx.LIST_AUTOSIZE)

终端中的结果是:TypeError: ListCtrl.InsertColumn(): arguments did not match any overloaded call: 重载 1:参数 1 具有意外类型“View1” 重载 2:参数 1 具有意外类型“View1”

我尝试删除 self 参数,保留为 tabla.InsertColumn (0, 'NOMBRE', format=wx.LIST_FORMAT_LEFT, width=wx.LIST_AUTOSIZE) ,但出现其他错误: wx._core.wxAssertionError:C++ 断言“InReportView()”在 DoInsertColumn() 中的 /home/vagrant/wxPython-4.0.6/ext/wxWidgets/src/generic/listctrl.cpp(5196) 失败:无法添加列在非报告模式下

【问题讨论】:

  • 我认为您应该从 InsertColumn 方法中删除 self 参数。 table.InsertColumn(0, 'NOMBRE', format=wx.LIST_FORMAT_LEFT, ......)
  • 我试过了,但出现了其他错误:tabla.InsertColumn (0, 'NOMBRE', format=wx.LIST_FORMAT_LEFT, width=wx.LIST_AUTOSIZE) wx._core.wxAssertionError: C++ assertion "InReportView( )" 在 DoInsertColumn() 中 /home/vagrant/wxPython-4.0.6/ext/wxWidgets/src/generic/listctrl.cpp(5196) 失败:无法在非报告模式下添加列

标签: python wxpython


【解决方案1】:

正如 Attila Toth 所说,删除 self 参数。自我自动传递给python中的方法。在这种情况下,selfwx.ListCtrl 实例,但随后您将 View1 实例作为列号参数传递。如果你仍然对self参数感到困惑here is a pretty good explanation of it

更新以解决新问题

第二个错误是不言自明的。使用样式标志 wx.LC_REPORT 而不是 wx.LC_LIST 创建 ListCtrl

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多