Skip to content

Instantly share code, notes, and snippets.

@LCPallares
Created June 15, 2018 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LCPallares/51d28d02e66be8eb8eb0d49ce28b92c3 to your computer and use it in GitHub Desktop.
Save LCPallares/51d28d02e66be8eb8eb0d49ce28b92c3 to your computer and use it in GitHub Desktop.
Abrir Nueva Ventana en PyQt5 (ventana secundaria)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ventana_principal.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from ventana_secundaria import Ui_ventana_secundaria
class Ui_ventana_principal(object):
def abrir_ventana(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_ventana_secundaria()
self.ui.setupUi(self.window)
ventana_principal.hide()
self.window.show()
def setupUi(self, ventana_principal):
ventana_principal.setObjectName("ventana_principal")
ventana_principal.resize(371, 297)
self.centralwidget = QtWidgets.QWidget(ventana_principal)
self.centralwidget.setObjectName("centralwidget")
self.boton_abrir = QtWidgets.QPushButton(self.centralwidget)
self.boton_abrir.setGeometry(QtCore.QRect(110, 140, 141, 51))
self.boton_abrir.setObjectName("boton_abrir")
self.boton_abrir.clicked.connect(self.abrir_ventana)
self.etiqueta = QtWidgets.QLabel(self.centralwidget)
self.etiqueta.setGeometry(QtCore.QRect(40, 40, 291, 41))
font = QtGui.QFont()
font.setPointSize(16)
self.etiqueta.setFont(font)
self.etiqueta.setObjectName("etiqueta")
ventana_principal.setCentralWidget(self.centralwidget)
self.barra_de_estado = QtWidgets.QStatusBar(ventana_principal)
self.barra_de_estado.setObjectName("barra_de_estado")
ventana_principal.setStatusBar(self.barra_de_estado)
self.retranslateUi(ventana_principal)
QtCore.QMetaObject.connectSlotsByName(ventana_principal)
def retranslateUi(self, ventana_principal):
_translate = QtCore.QCoreApplication.translate
ventana_principal.setWindowTitle(_translate("ventana_principal", "Ventana Principal"))
self.boton_abrir.setText(_translate("ventana_principal", "Abrir Ventana"))
self.etiqueta.setText(_translate("ventana_principal", "Haga clic para abrir la ventana"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ventana_principal = QtWidgets.QMainWindow()
ui = Ui_ventana_principal()
ui.setupUi(ventana_principal)
ventana_principal.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ventana_principal</class>
<widget class="QMainWindow" name="ventana_principal">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>297</height>
</rect>
</property>
<property name="windowTitle">
<string>Ventana Principal</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="boton_abrir">
<property name="geometry">
<rect>
<x>110</x>
<y>140</y>
<width>141</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Abrir Ventana</string>
</property>
</widget>
<widget class="QLabel" name="etiqueta">
<property name="geometry">
<rect>
<x>40</x>
<y>40</y>
<width>291</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Haga clic para abrir la ventana</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="barra_de_estado"/>
</widget>
<resources/>
<connections/>
</ui>
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'ventana_secundaria.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_ventana_secundaria(object):
def setupUi(self, ventana_secundaria):
ventana_secundaria.setObjectName("ventana_secundaria")
ventana_secundaria.resize(568, 109)
self.centralwidget = QtWidgets.QWidget(ventana_secundaria)
self.centralwidget.setObjectName("centralwidget")
self.etiqueta = QtWidgets.QLabel(self.centralwidget)
self.etiqueta.setGeometry(QtCore.QRect(100, 20, 371, 41))
font = QtGui.QFont()
font.setPointSize(22)
self.etiqueta.setFont(font)
self.etiqueta.setObjectName("etiqueta")
ventana_secundaria.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(ventana_secundaria)
self.statusbar.setObjectName("statusbar")
ventana_secundaria.setStatusBar(self.statusbar)
self.retranslateUi(ventana_secundaria)
QtCore.QMetaObject.connectSlotsByName(ventana_secundaria)
def retranslateUi(self, ventana_secundaria):
_translate = QtCore.QCoreApplication.translate
ventana_secundaria.setWindowTitle(_translate("ventana_secundaria", "Ventana Secundaria"))
self.etiqueta.setText(_translate("ventana_secundaria", "Bienvenido a esta ventana"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ventana_secundaria = QtWidgets.QMainWindow()
ui = Ui_ventana_secundaria()
ui.setupUi(ventana_secundaria)
ventana_secundaria.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ventana_secundaria</class>
<widget class="QMainWindow" name="ventana_secundaria">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>568</width>
<height>109</height>
</rect>
</property>
<property name="windowTitle">
<string>Ventana Secundaria</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="etiqueta">
<property name="geometry">
<rect>
<x>100</x>
<y>20</y>
<width>371</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>22</pointsize>
</font>
</property>
<property name="text">
<string>Bienvenido a esta ventana</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment