[Python] 纯文本查看 复制代码 from PySide6.QtWidgets import QApplication, QWidget
from 汽车宝UI import Ui_Form
import hello_rc
from PySide6.QtGui import QPixmap
from PySide6.QtCore import Slot
import mainCode
class MyWindow(QWidget, Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
# 将点击信号连接到槽函数
self.pushButton_2.clicked.connect(self.execute_imported_code)
# 槽函数,当 pushButton_2 被点击时执行引入的代码
@Slot()
def execute_imported_code(self):
# 直接运行 mainCode 模块中的代码
exec(open("mainCode.py", encoding='utf-8').read())
# 或者直接在这里执行引入的代码
print("PushButton 2 clicked, execute imported code here")
if __name__ == '__main__':
app = QApplication([])
window = MyWindow()
window.show()
app.exec()
[Python] 纯文本查看 复制代码 Traceback (most recent call last):
File "E:\PycharmPFile\XYJD\汽车之家\UI\05.py", line 20, in execute_imported_code
exec(open("mainCode.py", encoding='utf-8').read())
File "<string>", line 385, in <module>
File "<string>", line 295, in main
NameError: name 'get_band_response' is not defined
我单独运行没问题的 在pyside6里面调用就报错,为啥呢 |