Skip to content

Instantly share code, notes, and snippets.

@mivade
Last active January 15, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivade/e6ec2589e7160c03951f838fe5f18dac to your computer and use it in GitHub Desktop.
Save mivade/e6ec2589e7160c03951f838fe5f18dac to your computer and use it in GitHub Desktop.
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