PyQt5写一个Python代码执行器

编程入门 行业动态 更新时间:2024-10-14 02:25:18

PyQt5写一个Python代码<a href=https://www.elefans.com/category/jswz/34/1635012.html style=执行器"/>

PyQt5写一个Python代码执行器

# @Author : 小红牛
# 微信公众号:WdPython
import sys
from PyQt5.QtWidgets import QApplication, QLabel, QLineEdit, QPushButton, QVBoxLayout, QWidgetdef execute_code():# 获取输入的代码code = code_input.text()# 执行代码exec(code)# 创建应用程序和窗口
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle("我的Python代码执行器")
window.setGeometry(400, 400, 400, 200)# 创建界面组件
code_label = QLabel("输入要执行的Python代码:")
code_input = QLineEdit()
code_input.setFixedSize(400, 200)
execute_button = QPushButton("执行")
# 配置布局
layout = QVBoxLayout()
layout.addWidget(code_label)
layout.addWidget(code_input)
layout.addWidget(execute_button)
window.setLayout(layout)# 绑定按钮点击事件
execute_button.clicked.connect(execute_code)# 显示窗口
window.show()# 运行应用程序
sys.exit(app.exec_())

更多推荐

PyQt5写一个Python代码执行器

本文发布于:2023-12-03 07:43:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1652801.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:执行器   代码   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!