PyQt: 练习 信号与槽PyQt: 练习 信号与槽PyQt: 练习 信号与槽PyQt: 练习 信号与槽
  • 首页
  • 博客
  • 书签
  • 文件
  • 分析
  • 登录

PyQt: 练习 信号与槽

发表 admin at 2022年4月14日
类别
  • Practice
标签
import sys
from PyQt5.Qt import *


class Window_2(QWidget):
    def closeEvent(self, a0) -> None:
        self.slot_func()
        return super().closeEvent(a0)

    def close_signal(self, slot_func):
        self.slot_func = slot_func


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()
        self.open_window_2()

    def setup_ui(self):
        self.setWindowTitle("窗口1")
        self.resize(300, 300)

        self.label = QLabel(self)
        self.label.resize(200, 30)
        self.label.setStyleSheet("background-color:cyan")

        self.show()

    def open_window_2(self):
        self.window_2 = Window_2()
        self.window_2.setWindowTitle("窗口2")
        self.window_2.resize(200, 100)
        self.window_2_push_button = QPushButton(self.window_2)
        self.window_2_push_button.setText("按钮")

        def window_2_push_button_clicked():
            self.label.setText("窗口2按钮被点击了")

        self.window_2_push_button.clicked.connect(window_2_push_button_clicked)

        def window_2_closed():
            self.label.setText("窗口2被关闭了")

        self.window_2.close_signal(window_2_closed)

        self.window_2.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    sys.exit(app.exec_())

发表回复 取消回复

要发表评论,您必须先登录。

类别

  • Cat
  • Python
  • Django
  • Database
  • Html/CSS
  • JavaScript
  • Vue
  • RegExp
  • Maths/AI
  • PHP/Wordpress
  • Practice
  • Linux
  • Windows
  • Android
  • NAS
  • Software
  • Hardware
  • Network
  • SEO
  • English
  • Games
  • Recipes
  • General
  • Memorandum
  • Essays
  • 未分类

归档

©2015-2023 艾丽卡 Blog support@alaica.com
      ajax-loader