在Python PyQt中打开第二个窗口时出错

时间:2020-10-07 03:09:48

标签: python

我需要解决一个小问题,我有以下Python PyQt5代码,我在两个窗口上使用QT设计器,我只需要知道为什么单击but_conectar按钮不能打开第二个对话框窗口,非常感谢

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox , QDialog, QPushButton, QLabel
from PyQt5 import uic
import ctypes #GetSystemMetrics

class conexion(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.setMinimumSize(310,550)
        self.setMaximumSize(310,550)
        resolucion = ctypes.windll.user32
        resolucion_ancho = resolucion.GetSystemMetrics(0)
        resolucion_alto = resolucion.GetSystemMetrics(1)
        left = (resolucion_ancho / 2) - (self.frameSize().width() / 2)
        top = (resolucion_alto / 2) - (self.frameSize().height() / 2)
        self.move(left, top)
        uic.loadUi("conectar.ui", self)

    def showEvent(self, QShowEvent):
        self.bienv.setText("sicex")


class Ventana(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        uic.loadUi("principal.ui", self)
        self.setWindowTitle("Cambiando el título de la ventana")
        self.setMinimumSize(1800,900)
        self.setMaximumSize(1800,900)
        resolucion = ctypes.windll.user32
        resolucion_ancho = resolucion.GetSystemMetrics(0)
        resolucion_alto = resolucion.GetSystemMetrics(1)
        left = (resolucion_ancho / 2) - (self.frameSize().width() / 2)
        top = (resolucion_alto / 2) - (self.frameSize().height() / 2)
        self.move(left, top)
        self.but_conectar.clicked.connect(self.fn_conectar)

    def fn_conectar(self):
        self.conexion.exec_()

    def closeEvent(self, event):
        resultado = QMessageBox.question(self, "Salir ...", "¿Seguro que quieres salir de la aplicación?",
                                         QMessageBox.Yes | QMessageBox.No)
        if resultado == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()

app = QApplication(sys.argv)
_ventana = Ventana()
_ventana.show()
app.exec_()

0 个答案:

没有答案