by
0
8
12k
45
Top 1% !
Popular
Famous
Pearl of Wisdom
Tagged
Easy-to-find
Specified
OpenSource
Popularity: 305th place
Created
Modified Mar 18, 2014

Published on:

Architecturex86_64
LanguagePython
LicenseMIT_X11
OSLinux

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 http://eli.thegreenplace.net/2011/04/25/passing-extra-arguments-to-pyqt-slot/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12165/Using-lambda-function-to-pass-extra-argu?startLine=0"></iframe>
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