Skip to content

Instantly share code, notes, and snippets.

@hcosta
Last active September 7, 2018 16:05
Show Gist options
  • Save hcosta/0bc19080efba6ebcb3990e3963578efe to your computer and use it in GitHub Desktop.
Save hcosta/0bc19080efba6ebcb3990e3963578efe to your computer and use it in GitHub Desktop.
from PyQt5.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Hola mundo")
self.setFixedSize(400, 200)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
app.exec_()
from PyQt5.QtWidgets import QApplication, QDialog
class Dialog(QDialog):
def __init__(self, *args, **kwargs):
super(Dialog, self).__init__(*args, **kwargs)
self.setWindowTitle("Hola mundo")
self.setFixedSize(400, 200)
if __name__ == "__main__":
app = QApplication([])
dialog = Dialog()
dialog.show()
app.exec_()
from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QPushButton
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Hola mundo")
self.setFixedSize(400, 200)
self.button = QPushButton(self, text="Mostrar diálogo")
self.button.clicked.connect(self.show_dialog)
def show_dialog(self):
dialog = Dialog(self) # self hace referencia al padre
dialog.show()
class Dialog(QDialog):
def __init__(self, *args, **kwargs):
super(Dialog, self).__init__(*args, **kwargs)
self.setWindowTitle("Soy un popup")
self.setFixedSize(200, 100)
if __name__ == "__main__":
app = QApplication([])
dialog = MainWindow()
dialog.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment