问题描述
我的开发环境:
操作系统:windows xp
python: python-3.1.2.msi
python: python-3.1.2.msi
pyqt:PyQt-Py3.1-gpl-4.7.4-1.exe
pyqt: PyQt-Py3.1-gpl-4.7.4-1.exe
代码:
import sys
from PyQt4 import QtCore, QtGui
app = QtGui.QApplication(sys.argv)
s = QtCore.QtString()
sys.exit(app.exec_())
它总是向我展示
在模块"中
s = QtCore.QtString()
s = QtCore.QtString()
AttributeError: 'module' 对象没有属性 'QtString'
AttributeError: 'module' object has no attribute 'QtString'
我更改了代码:
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
app = QApplication(sys.argv)
s = QtString()
sys.exit(app.exec_())
然后它总是这样显示我:
Then it always show me like this:
在模块"中
s = QtString()
s = QtString()
NameError: name 'QtString' 未定义
NameError: name 'QtString' is not defined
我该怎么办?
推荐答案
这里解释了这个问题 http://inputvalidation.blogspot.com/2010/10/python3-pyqt4-and-missing-qstring.html
您无法加载 QString
的原因是 PyQt4 中缺少它(也许更早,谁知道).由于 Py3k 与 Py2k 不同,默认支持 Unicode,因此不需要该类.
The reason why you couldn't load QString
is that it is missing from PyQt4 (maybe earlier, who knows). Since Py3k, as opposed to Py2k, supports Unicode by default, there's no need in this class.
出于兼容性原因,您应该在 import
的某处使用此代码段,而不是 QString:
Instead of QString, for compatibility reasons, you should use this snippet somewhere around your import
's:
try:
from PyQt4.QtCore import QString
except ImportError:
QString = str
这篇关于AttributeError: 'module' 对象没有属性 'QtString'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!