Reference to object

Hi

I got a problem not knowing how to change a text of a QPushbutton in a QButtonGroup. Here is my code:

#!/usr/bin/python
import sys
from PyQt5.QtWidgets import (QApplication,QWidget,QVBoxLayout,QPushButton,QButtonGroup)

class panel(QWidget):
    
    def __init__(self):
        super().__init__()
        self.buildPanel()
        #self.buttonchecked()
        self.show()    
        
    def buildPanel(self):
        '''
        builds the panel
        '''
        vlayout=QVBoxLayout()
        self.setWindowTitle('ButtonGroup test')
        buttonGroup=QButtonGroup(self)
        buttonGroup.setExclusive(False)
        for pin in [23,25,21,56,164]:
            button=QPushButton(self)
            button.setCheckable(True)
            button.setText(str(pin))
            button.setObjectName(str(pin))
            buttonGroup.addButton(button)
            vlayout.addWidget(button)
        buttonGroup.buttonClicked.connect(self.buttonClick)      
        self.setLayout(vlayout)
        
    def buttonClick(self,button):
        pin=button.text()
        print(f'Button: {pin}')
        
    def buttonchecked(self):
        checked=[25,21]
        for button in checked:
            f"button{button}".setText('pressed')
    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    d=panel()
    sys.exit(app.exec())

The buttons are created here by a simple list. My question is how to access a specific button from the list from outside the function (e.g. to change it’s text)? The buttons 25 and 21 should be changed. I’m aware that the function buttonchecked doesn’t work, but it’s only to show what I meant.

Thanks

something like this?

    def buttonClick(self,button):
        pin=button.text()
        print(f'Button: {pin}')
        checked=[25,21]
        for val in checked:
            if str(val) in button.objectName():
                if button.isChecked():
                    button.setText('pressed')
                else:
                    button.setText(str(val))

Thank you.

That worked.