首页 > 编程语言 >Python 窗口界面跳转

Python 窗口界面跳转

时间:2024-08-18 15:48:18浏览次数:12  
标签:__ 界面 Python window2 self init window 跳转 window1

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())

标签:__,界面,Python,window2,self,init,window,跳转,window1
From: https://www.cnblogs.com/conpi/p/18365720

相关文章