0
我有一個MainWindow,我想打開一個新窗口。Pyqt 5新窗口崩潰主窗口
新窗口:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:\Users\Tareq\Desktop\table.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(703, 449)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(0, 0, 701, 401))
self.tableWidget.setRowCount(48)
self.tableWidget.setColumnCount(4)
self.tableWidget.setObjectName("tableWidget")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 703, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
我加入到我的主窗口下面的說明
self.pushButton_2.clicked.connect(self.create_new_window)
及以下功能:
def create_new_window(self):
from tableWindow import Ui_MainWindow
self.tableWindow = Ui_MainWindow
self.tableWinow.show()
但按下按鈕2後PROGRAMM沒有崩潰給定錯誤...
個過程完成,退出代碼爲1
什麼是'MainWindow'? – eyllanesc
我的主窗口PY文件如果我有一個按鈕@eyllanesc –
嘗試:'高清create_new_window(個體經營):從tableWindow進口Ui_MainWindow UI = Ui_MainWindow() self.tableWindow =的QMainWindow()ui.setupUi(self.tableWindow)自 .tableWindow.show()' – eyllanesc