在下面查看我的代码
main.py
从PyQt5.QtWidgets导入QApplication,QDialog,QWidget,QPushButton,QLineEdit,QComboBox,QMessageBox,QLabel,QFileDialog,QPlainTextEdit,QProgressBar,QLCDNumber,QCheckBox 从PyQt5.QtGui导入* 从PyQt5.QtWidgets导入QTableWidget,QTableWidgetItem 从表导入*
类主要(对象): def init (自我,frmwafermap): #frmwafermap = QtWidgets.QMainWindow()#从QMainWindow类创建主窗口 ui = Ui_frmwafermap() ui.setupUi(frmwafermap)
#ui = UI_frmwafermap(frmwafermap)
#ui = Ui_frmwafermap() #create an instance of frmwafermap
#ui.setupUi(frmwafermap) # initialize controls
frmwafermap.show() #shown the form
#print("....")
self.centralwidget = QtWidgets.QTableWidget(frmwafermap)
self.tablewafermap = QtWidgets.QTableWidget(self.centralwidget)
self.tablewafermap = QtWidgets.QTableWidget(self.centralwidget)
print(self.tablewafermap)
#self.tablewidget.setGeometry(QtCore.QRect(0, 0, 302, 302))
#self.tablewafermap.setAlternatingRowColors(True)
#self.tablewafermap.insertRow(100)
#self.tablewafermap.insertColumn(100)
self.tablewafermap.setRowCount(100)
self.tablewafermap.setColumnCount(100)
self.tablewafermap.setItem(1 , 100, QtWidgets.QTableWidgetItem("text1"))
self.tablewafermap.setItem(1 , 100, QtWidgets.QTableWidgetItem("text1"))
self.tablewafermap.setItem(1 , 100, QtWidgets.QTableWidgetItem("text1"))
self.tablewafermap.setItem(1, 100, QtWidgets.QTableWidgetItem("text1"))
#self.tablewafermap.setRowCount(200)
#self.tablewafermap.setColumnCount(200)
self.tablewafermap.resize(200,200)
def retranslateUi(self, frmwafermap):
_translate = QtCore.QCoreApplication.translate
如果名称 ==“ 主要”: 导入系统 应用= QtWidgets.QApplication(sys.argv) frmwafermap = QtWidgets.QMainWindow()#从QMainWindow类创建主窗口 #ui = Ui_frmwafermap() #ui = Ui_frmwafermap()#创建frmwafermap的实例 #ui.setupUi(frmwafermap)#初始化控件 #frmwafermap.show()#显示表格 #ex = 主要(frmwafermap) 例如= 主要(frmwafermap) sys.exit(app.exec _())
table.py 从PyQt5导入QtCore,QtGui,QtWidgets
Ui_frmwafermap类(对象): def setupUi(self,frmwafermap): frmwafermap.setObjectName(“ frmwafermap”) frmwafermap.resize(601,601) self.centralwidget = QtWidgets.QWidget(frmwafermap) self.centralwidget.setObjectName(“ centralwidget”) self.tblwafermap = QtWidgets.QTableWidget(self.centralwidget) self.tblwafermap.setGeometry(QtCore.QRect(0,0,602,661)) self.tblwafermap.setToolTip(“”) self.tblwafermap.setAlternatingRowColors(False) self.tblwafermap.setShowGrid(真) self.tblwafermap.setGridStyle(QtCore.Qt.SolidLine) self.tblwafermap.setCornerButtonEnabled(真) #self.tblwafermap.setRowCount(10) #self.tblwafermap.setColumnCount(10) self.tblwafermap.setObjectName(“ tblwafermap”) self.tblwafermap.horizontalHeader()。setVisible(False) self.tblwafermap.horizontalHeader()。setCascadingSectionResizes(False) self.tblwafermap.horizontalHeader()。setDefaultSectionSize(2) self.tblwafermap.horizontalHeader()。setMinimumSectionSize(1) self.tblwafermap.verticalHeader()。setVisible(False) self.tblwafermap.verticalHeader()。setDefaultSectionSize(2) self.tblwafermap.verticalHeader()。setMinimumSectionSize(1) self.tblwafermap.verticalHeader()。setSortIndicatorShown(False) frmwafermap.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(frmwafermap) self.menubar.setGeometry(QtCore.QRect(0,0,663 21)) self.menubar.setObjectName(“ menubar”) self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName(“ menuFile”) frmwafermap.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(frmwafermap) self.statusbar.setObjectName(“ statusbar”) frmwafermap.setStatusBar(self.statusbar) self.actionOpen = QtWidgets.QAction(frmwafermap) self.actionOpen.setObjectName(“ actionOpen”) self.actionExit = QtWidgets.QAction(frmwafermap) self.actionExit.setObjectName(“ actionExit”) self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionExit) self.menubar.addAction(self.menuFile.menuAction())
self.retranslateUi(frmwafermap)
QtCore.QMetaObject.connectSlotsByName(frmwafermap)
def resize(self,rows,col):
self.tablewafermap.setRowCount(rows)
self.tablewafermap.setColumnCount(col)
def retranslateUi(self, frmwafermap):
_translate = QtCore.QCoreApplication.translate
frmwafermap.setWindowTitle(_translate("frmwafermap", "Wafer Map Display"))
self.tblwafermap.setWhatsThis(_translate("frmwafermap", "Wafer Map"))
self.menuFile.setTitle(_translate("frmwafermap", "File"))
self.actionOpen.setText(_translate("frmwafermap", "Open"))
self.actionExit.setText(_translate("frmwafermap", "Exit"))
如果名称 ==“ 主要”: 导入系统 应用= QtWidgets.QApplication(sys.argv) frmwafermap = QtWidgets.QMainWindow() ui = Ui_frmwafermap() ui.setupUi(frmwafermap) frmwafermap.show() sys.exit(app.exec _())
最终结果将是打开带有x列网格的窗口 我输入的首先,我将直接在代码中输入行和列以进行尝试。 实际结果是空白屏幕,没有第x列的网格