You can use either partial
or anonymous functions in combination with only one, parametrized, function to accomplish all tasks. Both versions (using partial
and lambda
) are shown in the example:
from functools import partial
def setTrigger(self, pushButton,value):
pushButton.setText(value)
#other actions
def uiConfig(self):
##triggerbutton configuration
self.ui.triggerButton.setText("Software")
self.ui.triggerButton.setMenu(menu)
menu = QtGui.QMenu()
menu.addAction('Software', partial(self.setTrigger, self.ui.triggerButton, 'Software'))
menu.addAction('Hardware', lambda: self.setTrigger(self.ui.triggerButton, 'Hardware'))