PyQt5信号和槽 --使用lambda表达式为槽函数传递参数
Lambda表达式:匿名函数,也就是没有名字的函数
fun = lambda:print("hello world")
fun()
fun1 = lambda s,y:print(x,y)
fun1("a","b")
import sys
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QMessageBox, QApplication, QVBoxLayout, QWidget, \
QLabel, QMainWindow
'''
PyQt5信号和槽 --使用lambda表达式为槽函数传递参数
Lambda表达式:匿名函数,也就是没有名字的函数
fun = lambda:print("hello world")
fun()
fun1 = lambda s,y:print(x,y)
fun1("a","b")
'''
class LambdaSlotArgDemo(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("使用lambda表达式为槽函数传递参数")
button1 = QPushButton("按钮1")
button2 = QPushButton("按钮2")
layout = QHBoxLayout()
layout.addWidget(button1)
layout.addWidget(button2)
mainFrame = QWidget()
mainFrame.setLayout(layout)
self.setCentralWidget(mainFrame)
button1.clicked.connect(lambda :self.onButtonClick(10,20))
a = 19
button2.clicked.connect(lambda :self.onButtonClick(10,a))
button1.clicked.connect(lambda :QMessageBox.information(self,'结果','单击了button1'))
def onButtonClick(self,m,n):
print("m+n:",m+n)
QMessageBox.information(self,'结果',str(m+n))
if __name__ == '__main__':
app = QApplication(sys.argv)
win = LambdaSlotArgDemo()
win.show()
sys.exit(app.exec_())