我正在使用Python 3.4和PyQt5。
我是python和Qt的新手。我在使用Qt Designer创建的GUI中使用表时遇到了问题,特别是setItem()and item()函数,我编写了两个函数,每个函数都由一个按钮执行。
' addRow(self)'创建并QTableWidget用中的值填充行QLineEdit。
' sumCol(self)'遍历每一行,将一列的每一项添加到列表中,找到总数,然后打印到QLineEdit
我收到以下错误:
AttributeError: 'module' object has no attribute 'QTableWidgetItem'
Run Code Online (Sandbox Code Playgroud)
我的代码:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from test_1 import Ui_MainWindow
class TestApp(Ui_MainWindow):
def __init__(self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
self.addButton.clicked.connect(self.addRow)
self.sumColButton.clicked.connect(self.sumCol)
def addRow(self):
#Retrieve text from QLineEdit
x = str(self.x_input.text())
y = str(self.y_input.text())
z = str(self.z_input.text())
#Create a empty row at bottom of table
numRows = self.tableWidget.rowCount()
self.tableWidget.insertRow(numRows)
#Add text to the …Run Code Online (Sandbox Code Playgroud)