打开新窗口时,PyQt5窗口会保持退出状态

时间:2017-06-08 00:16:38

标签: python python-3.x pyqt pyqt5

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.8.2
#
# 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(733, 497)
        self.centralWidget = QtWidgets.QWidget(MainWindow)
        self.centralWidget.setObjectName("centralWidget")
        self.My_2 = QtWidgets.QPushButton(self.centralWidget)
        self.My_2.setGeometry(QtCore.QRect(0, 30, 101, 41))
        self.My_2.setStyleSheet("")
        self.My_2.setText("")
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../../Major Project/Add a game button 1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.My_2.setIcon(icon)
        self.My_2.setIconSize(QtCore.QSize(100, 100))
        self.My_2.setObjectName("My_2")
        self.My_3 = QtWidgets.QPushButton(self.centralWidget)
        self.My_3.setGeometry(QtCore.QRect(0, 80, 101, 41))
        self.My_3.setObjectName("My_3")
        self.My_3.clicked.connect(self.editbutton) #EDIT BUTTON
        self.My_4 = QtWidgets.QPushButton(self.centralWidget)
        self.My_4.setGeometry(QtCore.QRect(60, 260, 31, 31))
        self.My_4.setText("")
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("../../Major Project/settings button.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.My_4.setIcon(icon1)
        self.My_4.setIconSize(QtCore.QSize(32, 32))
        self.My_4.setObjectName("My_4")
        self.My_5 = QtWidgets.QPushButton(self.centralWidget)
        self.My_5.setGeometry(QtCore.QRect(0, 210, 101, 41))
        self.My_5.setObjectName("My_5")
        self.line_3 = QtWidgets.QFrame(self.centralWidget)
        self.line_3.setGeometry(QtCore.QRect(100, 0, 20, 341))
        self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.timeEdit = QtWidgets.QTimeEdit(self.centralWidget)
        self.timeEdit.setGeometry(QtCore.QRect(0, 300, 101, 22))
        self.timeEdit.setObjectName("timeEdit")
        self.scrollArea = QtWidgets.QScrollArea(self.centralWidget)
        self.scrollArea.setGeometry(QtCore.QRect(130, 30, 571, 271))
        self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        self.scrollAreaWidgetContents = QtWidgets.QWidget()
        self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 552, 269))
        self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
        self.graphicsView_2 = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
        self.graphicsView_2.setGeometry(QtCore.QRect(160, 30, 101, 81))
        self.graphicsView_2.setObjectName("graphicsView_2")
        self.graphicsView = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
        self.graphicsView.setGeometry(QtCore.QRect(30, 30, 101, 81))
        self.graphicsView.setObjectName("graphicsView")
        self.line_2 = QtWidgets.QFrame(self.scrollAreaWidgetContents)
        self.line_2.setGeometry(QtCore.QRect(10, 10, 531, 20))
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
        self.pushButton.setGeometry(QtCore.QRect(40, 110, 81, 23))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
        self.pushButton_2.setGeometry(QtCore.QRect(170, 110, 81, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.scrollArea.setWidget(self.scrollAreaWidgetContents)
        MainWindow.setCentralWidget(self.centralWidget)
        self.menuBar = QtWidgets.QMenuBar(MainWindow)
        self.menuBar.setGeometry(QtCore.QRect(0, 0, 733, 21))
        self.menuBar.setObjectName("menuBar")
        MainWindow.setMenuBar(self.menuBar)
        self.mainToolBar = QtWidgets.QToolBar(MainWindow)
        self.mainToolBar.setObjectName("mainToolBar")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        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"))
        self.My_3.setText(_translate("MainWindow", "Edit"))
        self.My_5.setText(_translate("MainWindow", "Help"))
        self.pushButton.setText(_translate("MainWindow", "PushButton"))
        self.pushButton_2.setText(_translate("MainWindow", "PushButton"))
    def editbutton(self):
        if __name__ == "__main__":
            import sys, editui
            app = QtWidgets.QApplication(sys.argv)
            MainWindow = QtWidgets.QMainWindow()
            ui = editui.Ui_MainWindow()
            ui.setupUi(MainWindow)
            MainWindow.show()
            sys.exit(app.exec_())


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_())

我需要帮助:当两个窗口打开一瞬间后,按下My_3按钮时窗口会一直退出。 editui.py是一个使用PyQt的通用自动生成的文件,所以就是这样。

如果有人可以帮助我,谢谢!

0 个答案:

没有答案