Python Qt学习(九)MainWindow

源代码:

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

# Form implementation generated from reading ui file 'qt_mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.tableView = QtWidgets.QTableView(self.centralwidget)
        self.tableView.setGeometry(QtCore.QRect(10, 10, 781, 521))
        self.tableView.setObjectName("tableView")



        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
        self.menubar.setObjectName("menubar")
        self.menuMain = QtWidgets.QMenu(self.menubar)
        self.menuMain.setObjectName("menuMain")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionAdd_New_Wiindow = QtWidgets.QAction(MainWindow)
        self.actionAdd_New_Wiindow.setObjectName("actionAdd_New_Wiindow")
        self.menuMain.addAction(self.actionAdd_New_Wiindow)
        self.menubar.addAction(self.menuMain.menuAction())
        self.actionAdd_New_Wiindow.triggered.connect(self.showWidget)


        self.Dialog = QtWidgets.QDialog(self.centralwidget)
        self.Dialog.setObjectName("Dialog")
        self.Dialog.resize(400, 300)
        self.Dialog.setModal(True)
        #self.Dialog.setWindowModality(Qt.WindowModality)
        self.Dialog.hide()

        self.buttonBox = QtWidgets.QDialogButtonBox(self.Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")

        
        self.buttonBox.accepted.connect(self.accept) # type: ignore
        self.buttonBox.rejected.connect(self.reject) # type: ignore

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.menuMain.setTitle(_translate("MainWindow", "Main"))
        self.actionAdd_New_Wiindow.setText(_translate("MainWindow", "Show Dialog"))
        self.Dialog.setWindowTitle(_translate("Dialog", "Dialog"))

    def show(self, Form):
        Form.show()
    
    def showWidget(self):
        self.Dialog.show()
                  
    def accept(self):
        self.Dialog.hide()
    
    def reject(self):
        self.Dialog.hide()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    Form=QtWidgets.QMainWindow()    
    main_win = Ui_MainWindow()    
    main_win.setupUi(Form)
    main_win.show(Form)
    
    sys.exit(app.exec())        

截图:

Python Qt学习(九)MainWindow_第1张图片

你可能感兴趣的:(python,qt,学习)