无法在UI文件中访问QSidget,PySide

时间:2015-10-12 08:58:43

标签: python python-2.7 pyside

(error "line 2 column 14: unknown constant e+307")

运行以下代码时出现此错误 test.py.

AttributeError: 'PySide.QtGui.QWidget' object has no attribute 'test_button'

test.ui文件有一个名为test_button的按钮

1 个答案:

答案 0 :(得分:0)

您无法以这种方式构建UI文件的路径:

os.path.dirname('__file__')

将始终返回空字符串, ui_file_path 将为'/ test.ui'

正确的方式:

module_dir = os.path.dirname(__file__)
ui_file_path = os.path.join(module_dir, 'test.ui')

但是当QUiLoader.load失败时,它会引发RuntimeError(在PySide 1.2.1上测试)。你的根文件系统上有一个ui文件吗?