@staticmethod def create_func(n): return lambda: print('button {}'.format(n+1)) for n in range(3): button = QtWidgets.QPushButton('button {}'.format(n+1), self) button.clicked.connect(self.create_func(n)) layout.addWidget(button)