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

相关推荐
databook2 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室2 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三4 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户2519162427117 小时前
Python之语言特点
python
刘立军8 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机11 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机12 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i13 小时前
django中的FBV 和 CBV
python·django
c8i13 小时前
python中的闭包和装饰器
python
这里有鱼汤17 小时前
小白必看:QMT里的miniQMT入门教程
后端·python