Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Multiline lambdas and why you'd want to use them
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class MainWindow(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('Multiline lambdas')
self.label = QLabel("Click the button")
self.button = QPushButton("Click me!")
self.button.clicked.connect(lambda: (
self.button.setEnabled(False),
self.button.setText("You clicked me!"),
self.label.setText("Woo!")
))
layout = QVBoxLayout()
layout.addWidget(self.label)
layout.addWidget(self.button)
self.setLayout(layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment