Tengo un problema al tratar de mandar un texto a un item en un tablewidget.
Este es el código que utilizo:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import uic
from PyQt5.Qt import *
class Principal(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
uic.loadUi("gif.ui",self)
self.table.setColumnWidth(0,200)
print(self.table.item(1,1).text())
self.s = self.table.item(0,1)
self.s.setText("s")
app = QApplication([])
p = Principal()
p.show()
app.exec_()
y este es error que recibo:
Traceback (most recent call last):
File "C:\Users\Angel\Desktop\gif.py", line 21, in <module>
p = Principal()
File "C:\Users\Angel\Desktop\gif.py", line 16, in __init__
self.s.setText("s")
AttributeError: 'NoneType' object has no attribute 'setText'
[Finished in 0.5s with exit code 1]
Anexo a esto como puedo hacer para eliminar una fila¿?
archivo .ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTableWidget" name="table">
<property name="geometry">
<rect>
<x>40</x>
<y>150</y>
<width>641</width>
<height>281</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>11</number>
</property>
<property name="midLineWidth">
<number>7</number>
</property>
<row>
<property name="text">
<string>1</string>
</property>
</row>
<row>
<property name="text">
<string>2</string>
</property>
</row>
<row>
<property name="text">
<string>3</string>
</property>
</row>
<column>
<property name="text">
<string>1</string>
</property>
</column>
<column>
<property name="text">
<string>2</string>
</property>
</column>
<column>
<property name="text">
<string>3</string>
</property>
</column>
<item row="1" column="1">
<property name="text">
<string>kjhkjhj</string>
</property>
</item>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>