python - Error when im trying add a column to a ListCtrl in wxPython(4.0.6)
问题描述
Im trying to add a column to a LisCtrl but i cannot
I tried to follow the documentation but i dont know what am i doing wrong
The documentation says : InsertColumn (self, col, heading, format=LIST_FORMAT_LEFT, width=LIST_AUTOSIZE)
(https://docs.wxpython.org/wx.ListCtrl.html#wx.ListCtrl.InsertColumn)
import wxclass 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)
The result in terminal is : TypeError: ListCtrl.InsertColumn(): arguments did not match any overloaded call: overload 1: argument 1 has unexpected type 'View1' overload 2: argument 1 has unexpected type 'View1'
i tried remove the self parameter leaving as tabla.InsertColumn (0, 'NOMBRE', format=wx.LIST_FORMAT_LEFT, width=wx.LIST_AUTOSIZE) , but appears other error : wx._core.wxAssertionError: C++ assertion "InReportView()" failed at /home/vagrant/wxPython-4.0.6/ext/wxWidgets/src/generic/listctrl.cpp(5196) in DoInsertColumn(): can't add column in non report mode
解决方案
正如 Attila Toth 所说,删除self
参数。自我自动传递给python中的方法。在这种情况下self
是wx.ListCtrl
实例,但是您将View1
实例作为列号参数传递。如果您仍然对self
参数感到困惑,这里有一个很好的解释
更新以解决新问题
第二个错误是不言自明的。ListCtrl
使用样式标志wx.LC_REPORT
而不是创建wx.LC_LIST
推荐阅读
- mysql - 如何获取mysql中每个用户的最新消息?
- javascript - 在 laravel7 中使用 ajax 和 jquery 导致下拉格式不显示在 html 中
- database - Postgresql 函数有不支持的返回
- reactjs - 'Spring' 不是从'react-spring' 导出的
- javascript - 为什么我必须在表单中的“提交”按钮上按两次才能看到反应中的日志?
- spring - 使用 Java 8 并行流 API 的 SMTP 身份验证异常
- flutter - 来自多个 Firebase 项目的 Flutter FCM 主题消息
- ios - 为什么UIButtons之间要加空格?
- java - 如何正确设置 jaxrs 客户端依赖项?
- sql - SQL根据sum计算延时