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

相关推荐
结衣结衣.3 分钟前
python中的函数介绍
java·c语言·开发语言·前端·笔记·python·学习
茫茫人海一粒沙6 分钟前
Python 代码编写规范
开发语言·python
原野心存7 分钟前
java基础进阶知识点汇总(1)
java·开发语言
林浩2337 分钟前
Python——异常处理机制
python
程序猿阿伟9 分钟前
《C++高效图形用户界面(GUI)开发:探索与实践》
开发语言·c++
暗恋 懒羊羊17 分钟前
Linux 生产者消费者模型
linux·开发语言·ubuntu
数据分析螺丝钉33 分钟前
力扣第240题“搜索二维矩阵 II”
经验分享·python·算法·leetcode·面试
五味香34 分钟前
C++学习,信号处理
android·c语言·开发语言·c++·学习·算法·信号处理
梓䈑1 小时前
【C语言】自定义类型:结构体
c语言·开发语言·windows