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_2d00 = "json转excel"

array_2d01 = "excel转json"

array_2d02 = "登录服务器"

array_2d10 = "文件去重"

array_2d11 = "统计成功率"

array_2d12 = "文件整理"

array_2d20 = "文件输出"

array_2d21 = "计算题统计"

array_2d22 = "知识题统计"

for i in range(3):

for j in range(3):

button = QPushButton(array_2dij, 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_())

相关推荐
Scott9999HH5 小时前
【IIoT流量实战】蒸汽管道阀门全关却仍有流量?用 Python 实现涡街信号 FFT 频谱分析与温压全补偿积算网关,深度拆解靠谱的涡街流量计厂家硬核技术标准
开发语言·python
码智社6 小时前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海6 小时前
python 列表、元组、集合和字典
开发语言·python
二十雨辰7 小时前
[爬虫]-Urllib
爬虫·python
萧瑟余晖7 小时前
JDK 26 新特性详解
java·开发语言
马优晨8 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯8 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_446260859 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao9 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest