执行器"/>
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代码执行器
发布评论