pyqt点击按钮执行脚本

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_())

相关推荐
毕设源码-邱学长4 小时前
【开题答辩全过程】以 基于Java的学校住宿管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言
rookieﻬ°5 小时前
PHP框架漏洞
开发语言·php
猿界零零七5 小时前
pip install mxnet 报错解决方案
python·pip·mxnet
炸膛坦客6 小时前
单片机/C/C++八股:(二十)指针常量和常量指针
c语言·开发语言·c++
兑生6 小时前
【灵神题单·贪心】1481. 不同整数的最少数目 | 频率排序贪心 | Java
java·开发语言
炸膛坦客7 小时前
单片机/C/C++八股:(十九)栈和堆的区别?
c语言·开发语言·c++
零雲7 小时前
java面试:了解抽象类与接口么?讲一讲它们的区别
java·开发语言·面试
不只会拍照的程序猿7 小时前
《嵌入式AI筑基笔记02:Python数据类型01,从C的“硬核”到Python的“包容”》
人工智能·笔记·python
Jay_Franklin7 小时前
Quarto与Python集成使用
开发语言·python·markdown
2401_831824968 小时前
代码性能剖析工具
开发语言·c++·算法