PyQt- 按钮操作

PyQt- Button Manipulation

如何使用 'boxXY' 形式的 Qt 设计器对象名称,其中 X 是行值,Y 值是 python 二维列表的列值;

import sys,os
from PyQt5 import QtCore, QtGui, uic
rowsColumns=[[],[],[],[],[],[],[],[],[],[]]##Current grid values

allScreens=uic.loadUiType("newSudokuScreens.ui")[0]

class aWindowClass(QtGui.QMainWindow, allScreens):
    def __init__(self, parent=none):
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.GPScreen.setVisible(True)
        self.CPScreen.setVisible(False)
        self.DSScreen.setVisible(False)
        self.HTPScreen.setVisible(False)
        self.MMScreen.setVisible(False)
        self.NPSUScreen.setVisible(False)
        self.PSIScreen.setVisible(False)
        self.RUPScreen.setVisible(False)
        self.SPUScreen.setVisible(False)
        self.box00.clicked.connect(self.findRowColumn)
    
    def findRowColumn(self):
        row=#4th character of button name
        column=#5th character of button
        numberWanted=int(input('enter value wanted')) #is part of UI but making row and column value work will help make this work
        rowsColumns[row][column]=numberWanted
    
for i in range(0,9):
    for j in range(0,9):
        rowsColumns[i].append(0) #fill grid with necessary 81 spaces for sudoku
    print(rowsColumns[i])
    
app=QtGui.QApplication(sys.argv)
aWindow=aWindowClass(None)
aWindow.show()
app.exec_()

例如,如果单击按钮 box56 我想将 box56 作为变量传递,然后在单击框时的过程中,行将设置为 5,列将设置为 6,然后将其附加到该位置在二维列表中。

提前致谢。

独立于@eyllanesc 提出的,很容易从插槽中找到发送信号的对象及其属性。

在这里你可以做:

def findRowColumn(self):
    button_name = self.sender().text()   # gets the text of the button
    row = int(button_name[3]) # 4th character of button name
    column = int(button_name[4]) # 5th character of button
    numberWanted = int(
        input('enter value wanted'))  # is part of UI but making row and column value work will help make this work
    rowsColumns[row][column] = numberWanted