Python - PyQT5 COMO CERRAR UNA VENTANA Y ABRIR OTRA

 
Vista:
sin imagen de perfil
Val: 2
Ha disminuido su posición en 18 puestos en Python (en relación al último mes)
Gráfica de Python

PyQT5 COMO CERRAR UNA VENTANA Y ABRIR OTRA

Publicado por fernando (2 intervenciones) el 24/01/2020 08:51:02
Hola! Estoy desarrollando un Proyecto que este comunicando Base de Datos de MySQL con PyQt5 pero me estanque en una parte muy tonta a mi parecer, porque no he podido solucionarlo, quiero abrir una ventana"Ingreso" desde una ventana llamada "base", e inmediatamente que se abra la ventana"Ingreso" se cierre la ventana"base" pero el problema ocurre cuando trato de realizar los metodos comunes porque me crashean el codigo, he intentado diversas maneras.

self.close()
self.exit()
self.quit()
self.exec_()
self.destroy()

y al momento de correr esa parte que activa la ventana "Ingreso" se cae el programa o me cierran ambas ventanas, alguna solucion? Saludos

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox
from PyQt5 import uic, QtWidgets
from PyQt5.QtCore import pyqtSignal, QObject
 
class Ventana_Base(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(523, 358)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        #DEFINICIONES DEL MARCO
        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(30, 0, 471, 311))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.frame.setFont(font)
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        #DEFINICIONES DEL TAB
        self.tabWidget = QtWidgets.QTabWidget(self.frame)
        self.tabWidget.setGeometry(QtCore.QRect(30, 60, 341, 211))
        self.tabWidget.setObjectName("tabWidget")
        #DEFINICION DEL TAB PRODUCTO
        self.producto = QtWidgets.QWidget()
        self.producto.setObjectName("producto")
        #DEFINICION DE LA TABLA DEL TAB PRODUCTO
        self.tableView = QtWidgets.QTableView(self.producto)
        self.tableView.setGeometry(QtCore.QRect(5, 1, 321, 181))
        self.tableView.setObjectName("tableView")
        self.tabWidget.addTab(self.producto, "")
        #DEFINICION DEL TAB CARRUSEL
        self.carrusel = QtWidgets.QWidget()
        self.carrusel.setObjectName("carrusel")
        #DEFINICION DE LA TABLA DEL TAB CARRUSEL
        self.tableView_2 = QtWidgets.QTableView(self.carrusel)
        self.tableView_2.setGeometry(QtCore.QRect(5, 0, 321, 181))
        self.tableView_2.setObjectName("tableView_2")
        self.tabWidget.addTab(self.carrusel, "")
        #DEFINICION DEL LABEL TITULO
        self.titulo = QtWidgets.QLabel(self.frame)
        self.titulo.setGeometry(QtCore.QRect(110, 10, 231, 51))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.titulo.setFont(font)
        self.titulo.setObjectName("titulo")
        MainWindow.setCentralWidget(self.centralwidget)
        #DEFINICIONES DEL MENUBAR
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 523, 21))
        self.menubar.setObjectName("menubar")
        #DEFINICION DE FILE
        self.menuFile = QtWidgets.QMenu(self.menubar)
        self.menuFile.setObjectName("menuFile")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        #DEFINICION DE LA OPCION INGRESO DEL MENU FILE
        self.actionINGRESO = QtWidgets.QAction(MainWindow)
        self.actionINGRESO.setObjectName("actionINGRESO")
        self.menuFile.addAction(self.actionINGRESO)
        self.menubar.addAction(self.menuFile.menuAction())
 
        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
 
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.producto), _translate("MainWindow", "Producto"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.carrusel), _translate("MainWindow", "Carrusel"))
        self.titulo.setText(_translate("MainWindow", "Base de Datos"))
        self.menuFile.setTitle(_translate("MainWindow", "File"))
        self.actionINGRESO.setText(_translate("MainWindow", "INGRESO"))
        #CODIGO ESCRITO
        self.actionINGRESO.triggered.connect(self.Ingreso_Window)
 
    def Ingreso_Window(self):
        from ingreso import Ventana_Ingreso
 
 
 
        print("se abrio ventana Ingreso")
        self.ventana=QtWidgets.QMainWindow()
        self.ui=Ventana_Ingreso()
        self.ui.setupUi(self.ventana)
        self.ventana.show()
        #self.Ventana_Base.exit()
 
 
 
 
 
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ventana_Base()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())


closewindows
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de José Manuel
Val: 54
Ha disminuido su posición en 2 puestos en Python (en relación al último mes)
Gráfica de Python

PyQT5 COMO CERRAR UNA VENTANA Y ABRIR OTRA

Publicado por José Manuel (19 intervenciones) el 27/01/2020 15:57:36
Hola:

Pues con el código que indicas funciona todo hasta que pulso en [Ingreso] que me tira el error:

1
2
3
4
in Ingreso_Window
    from ingreso import Ventana_Ingreso
 
ModuleNotFoundError: No module named 'ingreso'

Porque falta el código para ingreso, lógicamente. No he podido probar más. Un saludo,
https://obelearningservices.com/blog/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

PyQT5 COMO CERRAR UNA VENTANA Y ABRIR OTRA

Publicado por Juan Diego (1 intervención) el 15/09/2020 02:48:48
Hola men ojala no sea tarde, tenia la misma pregunta y explore metodos y lo encontre!

app.closeAllWindows()

ese es el metodo mira;

instancia_de_la_clase.closeAllWindows()

deberias usar el vscode pones un punto y te salen TODOS los metodos

Un saludo :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar