Last active
January 15, 2018 16:54
-
-
Save mivade/e6ec2589e7160c03951f838fe5f18dac to your computer and use it in GitHub Desktop.
Multiline lambdas and why you'd want to use them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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