Using lambda function to pass extra argument to slots using PyQt4 python

When programming with PyQt is useful to pass extra arguments to slots callback methods, in order to execute some code when a UI control's action is invoked.

In this example you can see the usage of lambda expression to pass the extra argument to the method invoked when pressing a button.

Thanks to
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
self.greeting = QLabel('', self) # Create the build button with its caption self.build_button = QPushButton('&Build Greeting', self) # Connect the button's clicked signal to AddControl self.build_button.clicked.connect(lambda: self.AddControl('fooData')) def AddControl(self, name): self.greeting.setText('%s!' % (name))
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus