class NineGridApp(QWidget):
def init(self):
super().init()
self.initUI()
def initUI(self):
self.setWindowTitle('测试常见的操作')
self.setGeometry(100, 100, 1800, 1800)
layout = QGridLayout()
创建一个3x3的二维数组
rows = 3
cols = 3
array_2d = [[0 for _ in range(cols)] for _ in range(rows)]
修改特定位置的元素
array_2d[0][0] = "json转excel"
array_2d[0][1] = "excel转json"
array_2d[0][2] = "登录服务器"
array_2d[1][0] = "文件去重"
array_2d[1][1] = "统计成功率"
array_2d[1][2] = "文件整理"
array_2d[2][0] = "文件输出"
array_2d[2][1] = "计算题统计"
array_2d[2][2] = "知识题统计"
for i in range(3):
for j in range(3):
button = QPushButton(array_2d[i][j], self)
res=i+j*3
layout.addWidget(button, i, j)
设置按钮的大小
button.setFixedSize(150, 150)
button.clicked.connect(self.showMessageBox)
设置按钮的颜色
button.setStyleSheet("background-color: blue; color: white;")
self.setLayout(layout)
self.show()
def json_to_excel(self):
print("AAAAA")
def excel_to_json(self):
print("BBBBB")
def showMessageBox(self):
sender = self.sender() # 获取发送信号的按钮
print(sender)
button_text = sender.text()
print(button_text)
if button_text=='json转excel':
dialog = RegisterDialog()
dialog.exec_() # 显示注册对话框
self.json_to_excel()
elif button_text=='excel转json':
self.excel_to_json()
elif button_text=='登录服务器':
pass
QMessageBox.information(self, '提示', f'helo')
if name == 'main':
app = QApplication(sys.argv)
window = NineGridApp()
sys.exit(app.exec_())