I'm starting to learn OOP using PyQt5, so I'm trying to make a window with a button and when the button is clicked, I want to show a new window. I wrote this code but it doesn't work, it just shows the window with the button, but the button doesn't do anything, it seems like it just waits, but it doesn't give me any mistakes neither
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
class Window2(QWidget):
def __init__(self, parent=None):
super(Window2, self).__init__(parent)
class Window(QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.init_ui()
def init_ui(self):
self.btn = QPushButton("Push Me")
layout = QVBoxLayout()
layout.addWidget(self.btn)
self.setLayout(layout)
self.setWindowTitle("PyQt5 double window")
self.btn.clicked.connect(self.btn_clk)
self.newindow = Window2(self)
self.show()
def btn_clk(self):
self.newindow.show()
app = QApplication(sys.argv)
a_window = Window()
sys.exit(app.exec_())
This question guided me PyQT: how to open new window but it's written in PyQt4 and I'm not sure about the differences betweent these two.