我无法在PySide2中导入QtScript。我不明白为什么以及如何做。这是PySide2示例文件中的演示代码。
我可以导入QtWidgets,QtCore等。
"""PySide2 port of the script/helloscript example from Qt v5.x"""
import sys
from PySide2 import QtWidgets, QtScript
from PySide2.QtWidgets import QApplication
app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
#app = QApplication.instance()
if app is None:
app = QApplication(sys.argv)
engine = QtScript.QScriptEngine()
button = QtWidgets.QPushButton()
scriptButton = engine.newQObject(button)
engine.globalObject().setProperty("button", scriptButton)
engine.evaluate("button.text = 'Hello World from PySide2!'")
engine.evaluate("button.styleSheet = 'font-style: italic'")
engine.evaluate("button.show()")
sys.exit(app.exec_())
> ImportError: cannot import name 'QtScript' from 'PySide2'
> (C:\Anaconda3\lib\site-packages\PySide2\__init__.py)
In the "__init__.py",the first port is like this.
__all__ = list("Qt" + body for body in
"Core;Gui;Widgets;PrintSupport;Sql;Network;Test;Concurrent;WinExtras;Xml;XmlPatterns;Help;Multimedia;MultimediaWidgets;OpenGL;Positioning;Location;Qml;Quick;QuickWidgets;RemoteObjects;Scxml;Sensors;TextToSpeech;Charts;Svg;DataVisualization;UiTools;AxContainer;WebChannel;WebEngineCore;WebEngine;WebEngineWidgets;WebSockets;3DCore;3DRender;3DInput;3DLogic;3DAnimation;3DExtras"
.split(";"))