如何执行 QRandomGenerator.global() 方法
How to execute QRandomGenerator.global() method
我正在使用 spyder。
当我 运行 我的代码使用 QRandomGenerator.global()
方法时,抛出错误。
因为global
是预定的名字
from PySide2 import QtCore
import PySide2
import os, sys
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
def main():
app = QtCore.QCoreApplication(sys.argv) if QtCore.QCoreApplication.instance() is None else QtCore.QCoreApplication.instance()
r = QtCore.QRandomGenerator.global()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
所有在 Python 中被命名为保留关键字的 Qt 函数(如 QTextDocument.print()
或 QWidget.raise()
)都使用下划线后缀。
r = QtCore.QRandomGenerator.global_()
我正在使用 spyder。
当我 运行 我的代码使用 QRandomGenerator.global()
方法时,抛出错误。
因为global
是预定的名字
from PySide2 import QtCore
import PySide2
import os, sys
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
def main():
app = QtCore.QCoreApplication(sys.argv) if QtCore.QCoreApplication.instance() is None else QtCore.QCoreApplication.instance()
r = QtCore.QRandomGenerator.global()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
所有在 Python 中被命名为保留关键字的 Qt 函数(如 QTextDocument.print()
或 QWidget.raise()
)都使用下划线后缀。
r = QtCore.QRandomGenerator.global_()