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

相关推荐
宸津-代码粉碎机2 分钟前
Spring 6.0+Boot 3.0实战避坑全指南:5大类高频问题与解决方案(附代码示例)
java·数据仓库·hive·hadoop·python·技术文档编写
傻啦嘿哟2 分钟前
Python自动整理音乐文件:按艺术家和专辑分类歌曲
数据库·python·分类
笃行客从不躺平4 分钟前
ThreadLocal 复习一
java·开发语言
weixin_462446237 分钟前
基于 Flask + lunar-python 的农历转换 API 实战(公历 ↔ 农历 / 干支 / 生肖 / 节日)
python·flask·节日
yangSnowy13 分钟前
PHP的运行模式
开发语言·php
无限进步_18 分钟前
【C语言】用队列实现栈:数据结构转换的巧妙设计
c语言·开发语言·数据结构·c++·链表·visual studio
weixin_5795996620 分钟前
编写一个程序,输入两个数字的加减乘除余数(Python版)
开发语言·python
liu****23 分钟前
02_Pandas_数据结构
数据结构·python·pandas·python基础
CYTElena28 分钟前
JAVA关于集合的笔记
java·开发语言·笔记
我是唐青枫35 分钟前
深入理解 C#.NET Parallel:并行编程的正确打开方式
开发语言·c#·.net