简体   繁体   English

无法使用Python导入Loader模块

[英]Unable to import Loader modules with Python

I am a beginner with python and started using Eclipse very recently. 我是python的初学者,最近才开始使用Eclipse。 I am using Qt-designer and created a file named MyWidget.ui, but while running the program I receive an error: 我正在使用Qt-designer并创建了一个名为MyWidget.ui的文件,但是在运行程序时出现错误消息:

from PyQt4.uic.Loader.loader import DynamicUILoader 从PyQt4.uic.Loader.loader导入DynamicUILoader
ImportError: No module named Loader.loader ImportError:没有名为Loader.loader的模块

import sys
from PyQt4 import QtGui, uic

class MyWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        uic.loadUi('MyWidget.ui', self)
        self.show()

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    MyWindow.show()
    sys.exit(app.exec_())

1 Design a user interface in QT4 Designer. 1在QT4 Designer中设计一个用户界面。 Save as a .ui file (XML). 另存为.ui文件(XML)。

2 Generate Python code from the UI file using pyuic. 2使用pyuic从UI文件生成Python代码。

pyuic4.bat -x myForm.ui > myForm.py On Windows it's bat file pyuic4 -x myForm.ui > myForm.py On Linux it's a script pyuic4.bat -x myForm.ui> myForm.py在Windows上是蝙蝠文件pyuic4 -x myForm.ui> myForm.py在Linux上是脚本

3 Test the UI. 3测试UI。 The '-x' option to pyuic causes it to emit a built-in test program so you can just run myForm.py from the command line to test it. pyuic的'-x'选项使它发出内置的测试程序,因此您只需从命令行运行myForm.py即可对其进行测试。

4 Create a python wrapper with the event loop in it. 4创建一个带有事件循环的python包装器。 For example, this is similar to what the '-x' option gives you. 例如,这类似于'-x'选项提供的内容。

将一个空的__init__.py文件放在“ \\ site-packages \\ PyQt4 \\ uic \\ Loader”子目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM