ok just to close close this thread off. Could not get Eval() to work but Exec() worked well , but I decided to rewrite the app using an array of buttons populated from within the application. This was non trivial cause of python arrays peculiarities but here is the code snippet for future ref. This creates an 8x16 array of buttons in an array declared inside the Qt MainWindow Class (this avoids the use of globals, don't even go three ) Code: #Here is the MainWindow Class with an array called ledArray declared. class MainWindow(QMainWindow, Ui_MainWindow): ledArray=[] def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setupUi(self) Here is the initialization routine to create the array of buttons in the Main.py and inserts them into the UI created by Qt Designer, where I had placed a grid layout in the main window to accept my buttons, all pre-styled to look nice. Code: def initled(): for r in range(8): MainWindow.ledArray.append([]) for c in range(16): MainWindow.ledArray[r].append(QtGui.QPushButton()) MainWindow.ledArray[r][c].setCheckable(True) MainWindow.ledArray[r][c].setMinimumSize(QtCore.QSize(45, 45)) ui.gridLayout.addWidget(MainWindow.ledArray[r][c], r, c) And I can change all attributes at once now with loop. Code: for r in range(8): for c in range(16): self.ledArray[r][c].setChecked(self.ledState) and here is the result Mike C
#Here is the MainWindow Class with an array called ledArray declared. class MainWindow(QMainWindow, Ui_MainWindow): ledArray=[] def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setupUi(self)
def initled(): for r in range(8): MainWindow.ledArray.append([]) for c in range(16): MainWindow.ledArray[r].append(QtGui.QPushButton()) MainWindow.ledArray[r][c].setCheckable(True) MainWindow.ledArray[r][c].setMinimumSize(QtCore.QSize(45, 45)) ui.gridLayout.addWidget(MainWindow.ledArray[r][c], r, c)
for r in range(8): for c in range(16): self.ledArray[r][c].setChecked(self.ledState)