2

I am a beginner with python and started using Eclipse very recently. I am using Qt-designer and created a file named MyWidget.ui, but while running the program I receive an error:

from PyQt4.uic.Loader.loader import DynamicUILoader
ImportError: No module named 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_())
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • What platform are you on? Are you sure you've installed all the necessary pyqt packages? With some minor corrections, the above example script works as expected for me. – ekhumoro Nov 23 '13 at 20:59

2 Answers2

1

1 Design a user interface in QT4 Designer. Save as a .ui file (XML).

2 Generate Python code from the UI file using pyuic.

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

3 Test the 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.

4 Create a python wrapper with the event loop in it. For example, this is similar to what the '-x' option gives you.

Kozak Poprostu
  • 133
  • 2
  • 9
0

Put an empty __init__.py file in the '\site-packages\PyQt4\uic\Loader' sub-directory.

Ninga
  • 689
  • 7
  • 14