Is it possible to pass variables through slots so I can print out certain text? Trying to pass variable \'DiffP\' which is defined in another function to slot.
\'Dif
The problem can be solved in 2 ways:
In general:
obj.signal.connect(lambda param1, param2, ..., arg1=val1, arg2= value2, ... : fun(param1, param2,... , arg1, arg2, ....))
def fun(param1, param2,... , arg1, arg2, ....):
[...]
where:
In your case:
self.buttonGroup.buttonClicked['int'].connect(lambda i: self.input(i, "text"))
@pyqtSlot(int)
def input(self, button_or_id, DiffP):
if isinstance(button_or_id, int):
if button_or_id == 0:
self.TotalInput[0].setText(DiffP)
elif button_or_id == 1:
self.TotalInput[54].setText('1')
functools.partial
:In general:
obj.signal.connect(partial(fun, args1, arg2, ... ))
def fun(arg1, arg2, ..., param1, param2, ...):
[...]
where:
In your case:
from functools import partial
[...]
self.buttonGroup.buttonClicked['int'].connect(partial(self.input, "text"))
@pyqtSlot(int)
def input(self, DiffP, button_or_id):
if isinstance(button_or_id, int):
if button_or_id == 0:
self.TotalInput[0].setText(DiffP)
elif button_or_id == 1:
self.TotalInput[54].setText('1')