import sys
from PySide6.QtWidgets import QApplication, QPushButton,QWidget
class window_1(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Window 1')
self.resize(400,300)
self.button1 = QPushButton('Button1',self)
self.button1.move(100,50)
class window_2(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Window 2')
self.resize(400,300)
self.button2 = QPushButton('Button2',self)
self.button2.move(100,50)
class switcher:
def __init__(self, window_1,window_2):
self.window1 = window_1
self.window2 = window_2
self.window1.button1.clicked.connect(self.switch_to_window2)
self.window2.button2.clicked.connect(self.switch_to_window1)
def switch_to_window2(self):
self.window1.hide()
self.window2.show()
def switch_to_window1(self):
self.window2.hide()
self.window1.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
window_1 = window_1()
window_2 = window_2()
s = switcher(window_1,window_2)
window_1.show()
sys.exit(app.exec())