PyQt5写一个Python代码执行器

PyQt5写一个Python代码执行器_第1张图片

# @Author : 小红牛
# 微信公众号:WdPython
import sys
from PyQt5.QtWidgets import QApplication, QLabel, QLineEdit, QPushButton, QVBoxLayout, QWidget

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

你可能感兴趣的:(我的Python教程,qt,python,开发语言)