piaoyiren 2023-04-11 09:25 采纳率: 58.8%
浏览 27
已结题

pyqt5 的问题一个窗口调用另一个

如何在主窗口调用并显示Dialog
我代码如下:


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

# Form implementation generated from reading ui file '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
import sys

from PyQt5.QtWidgets import QDialog

from liver.visitor import Ui_VisitorDialog


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(943, 688)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.liverButton = QtWidgets.QPushButton(self.centralwidget)
        self.liverButton.setGeometry(QtCore.QRect(330, 70, 221, 71))
        self.liverButton.setObjectName("liverButton")
        self.liverButton.clicked.connect(self.liverLoginConnect)
        self.visitorButton = QtWidgets.QPushButton(self.centralwidget)
        self.visitorButton.setGeometry(QtCore.QRect(330, 280, 221, 71))
        self.visitorButton.setObjectName("visitorButton")
        self.adminButton = QtWidgets.QPushButton(self.centralwidget)
        self.adminButton.setGeometry(QtCore.QRect(330, 470, 221, 71))
        self.adminButton.setObjectName("adminButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 943, 26))
        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", "人脸识别门禁系统"))
        self.liverButton.setText(_translate("MainWindow", "住户入口"))
        self.visitorButton.setText(_translate("MainWindow", "外来人员入口"))
        self.adminButton.setText(_translate("MainWindow", "管理员功能管理"))
    def liverLoginConnect(self):
        # self.hide()
        print("-----------")
        diago = QDialog(self)
        ui = Ui_VisitorDialog(self)
        ui.setupUi(diago)
        print("++++++++++++")
        # ui.open()
        # ui.setupUi(diago)
        # diago.show()
        # super().__init__(parent)

if __name__ == "__main__":

    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())


# -*- coding: utf-8 -*-
import sys

# Form implementation generated from reading ui file 'visitor.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.QtWidgets import QDialog


class Ui_VisitorDialog(object):
    def setupUi(self, VisitorDialog):
        VisitorDialog.setObjectName("VisitorDialog")
        # VisitorDialog.setWindowModality(QtCore.Qt.WindowModal)
        VisitorDialog.resize(1355, 823)

        self.showFaceImage = QtWidgets.QLabel(VisitorDialog)
        self.showFaceImage.setGeometry(QtCore.QRect(60, 50, 591, 451))
        self.showFaceImage.setText("")
        self.showFaceImage.setObjectName("showFaceImage")
        self.signInFaceBtn = QtWidgets.QPushButton(VisitorDialog)
        self.signInFaceBtn.setGeometry(QtCore.QRect(50, 590, 181, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(False)
        font.setWeight(50)
        self.signInFaceBtn.setFont(font)
        self.signInFaceBtn.setObjectName("signInFaceBtn")
        self.faceIdentifyBtn = QtWidgets.QPushButton(VisitorDialog)
        self.faceIdentifyBtn.setGeometry(QtCore.QRect(330, 590, 181, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(False)
        font.setWeight(50)
        self.faceIdentifyBtn.setFont(font)
        self.faceIdentifyBtn.setObjectName("faceIdentifyBtn")
        self.registInfo = QtWidgets.QPushButton(VisitorDialog)
        self.registInfo.setGeometry(QtCore.QRect(50, 710, 181, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(False)
        font.setWeight(50)
        self.registInfo.setFont(font)
        self.registInfo.setObjectName("registInfo")
        self.updateInfoBtn = QtWidgets.QPushButton(VisitorDialog)
        self.updateInfoBtn.setGeometry(QtCore.QRect(330, 710, 181, 81))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(False)
        font.setWeight(50)
        self.updateInfoBtn.setFont(font)
        self.updateInfoBtn.setObjectName("updateInfoBtn")
        self.label = QtWidgets.QLabel(VisitorDialog)
        self.label.setGeometry(QtCore.QRect(770, 40, 101, 31))
        self.label.setObjectName("label")
        self.userNameText = QtWidgets.QLabel(VisitorDialog)
        self.userNameText.setGeometry(QtCore.QRect(940, 30, 211, 41))
        self.userNameText.setText("")
        self.userNameText.setObjectName("userNameText")
        self.label_5 = QtWidgets.QLabel(VisitorDialog)
        self.label_5.setGeometry(QtCore.QRect(770, 130, 101, 31))
        self.label_5.setObjectName("label_5")
        self.phoneText = QtWidgets.QLabel(VisitorDialog)
        self.phoneText.setGeometry(QtCore.QRect(940, 120, 211, 41))
        self.phoneText.setText("")
        self.phoneText.setObjectName("phoneText")
        self.sexText = QtWidgets.QLabel(VisitorDialog)
        self.sexText.setGeometry(QtCore.QRect(940, 200, 211, 41))
        self.sexText.setText("")
        self.sexText.setObjectName("sexText")
        self.label_8 = QtWidgets.QLabel(VisitorDialog)
        self.label_8.setGeometry(QtCore.QRect(770, 210, 101, 31))
        self.label_8.setObjectName("label_8")
        self.label_9 = QtWidgets.QLabel(VisitorDialog)
        self.label_9.setGeometry(QtCore.QRect(780, 310, 101, 31))
        self.label_9.setObjectName("label_9")
        self.buildingText = QtWidgets.QLabel(VisitorDialog)
        self.buildingText.setGeometry(QtCore.QRect(950, 300, 211, 41))
        self.buildingText.setText("")
        self.buildingText.setObjectName("buildingText")
        self.roomText = QtWidgets.QLabel(VisitorDialog)
        self.roomText.setGeometry(QtCore.QRect(950, 400, 211, 41))
        self.roomText.setText("")
        self.roomText.setObjectName("roomText")
        self.label_12 = QtWidgets.QLabel(VisitorDialog)
        self.label_12.setGeometry(QtCore.QRect(780, 410, 101, 31))
        self.label_12.setObjectName("label_12")
        self.photoText = QtWidgets.QLabel(VisitorDialog)
        self.photoText.setGeometry(QtCore.QRect(830, 530, 221, 251))
        self.photoText.setObjectName("photoText")

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

    def retranslateUi(self, VisitorDialog):
        _translate = QtCore.QCoreApplication.translate
        VisitorDialog.setWindowTitle(_translate("VisitorDialog", "Dialog"))
        self.signInFaceBtn.setText(_translate("VisitorDialog", "录入人脸"))
        self.faceIdentifyBtn.setText(_translate("VisitorDialog", "人脸识别"))
        self.registInfo.setText(_translate("VisitorDialog", "登记个人信息"))
        self.updateInfoBtn.setText(_translate("VisitorDialog", "修改信息"))
        self.label.setText(_translate("VisitorDialog", "用户名称:"))
        self.label_5.setText(_translate("VisitorDialog", "电话号码:"))
        self.label_8.setText(_translate("VisitorDialog", "用户性别:"))
        self.label_9.setText(_translate("VisitorDialog", "楼栋名称:"))
        self.label_12.setText(_translate("VisitorDialog", "房间编号:"))
        self.photoText.setText(_translate("VisitorDialog", "头像"))
# # if __name__ == "__main__":
#     def open(self):
#         app = QtWidgets.QApplication(sys.argv)
#         diago = QDialog()
#         ui = Ui_VisitorDialog()
#         ui.setupUi(diago)
#         diago.show()
#         sys.exit(app.exec_())
  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月19日
  • 已采纳回答 4月11日
  • 创建了问题 4月11日

悬赏问题

  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题
  • ¥20 bash代码推送不上去 git fetch origin master #失败了
  • ¥15 LOL外服加入了反作弊系统,现在游戏录像rofl文件离线都无法打开
  • ¥15 在centos7安装conda
  • ¥15 c#调用yolo3 dll文件获取的数据对不上
  • ¥20 WPF 如何实现多语言,label 和cs(live Charts)中是否都能翻译