什么是信号与槽 ?
对象之间的通信用的技术是信号与槽。发生特定事件时会发出信号,发出的信号要连接一个槽。现在我们创建一个Pyside 2信号和槽的例子。
from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
import sys
from PySide2.QtGui import QIcon
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Pyside2 QPushButton")
self.setGeometry(500,400,500,400)
self.setIcon()
self.setButton()
def setIcon(self):
appIcon = QIcon("icon.png")
self.setWindowIcon(appIcon)
def setButton(self):
btn1 = QPushButton("Quit", self)
btn1.move(50,100)
btn1.clicked.connect(self.quiteApp)
def quiteApp(self):
userInfo = QMessageBox.question(self, "Confirmation", "Do You Want To Quit The Application",
QMessageBox.Yes | QMessageBox.No)
if userInf