[Python] How in this circumstance do I arm each object in a list correctly? (PyQt4) [duplicate]

Discussão em 'Python' iniciado por Stack, Abril 3, 2025.

  1. Stack

    Stack Membro Participativo

    I know PyQt4 is far outdated by now but updating right now is not an option I have available. If anyone knows what my issue is I would really appreciate an explanation.

    My code here creates buttons within a layout which when clicked is meant to trigger the function. Issue is that the function IS triggered but no matter what square is clicked the square to the bottom right hand corner will be the one passed to the function as a parameter.

    gameSquareSize_width = 470//gameGridCollumns
    gameSquareSize_height = 470//gameGridRows
    btn_list = [[]]*gameGridRows
    for i in range (len(btn_list)):
    btn_list = ["0"]*gameGridCollumns
    print (btn_list)

    for x in range (0, gameGridRows):
    for y in range (0, gameGridCollumns):
    btn_list[x][y] = QtGui.QPushButton(player_1_frame)
    btn_list[x][y].setGeometry(QtCore.QRect((gameSquareSize_width*x),(gameSquareSize_height*y), gameSquareSize_width, gameSquareSize_height))
    btn_list[x][y].setStyleSheet("background-color: rgb(255, 255, 255)") #Sets stylesheet
    btn_list[x][y].clicked.connect(lambda: playGameWindow.squareClicked(self, btn_list[x][y]))

    Continue reading...

Compartilhe esta Página