If you look at the comments at the top of the generated file, you will see this line:
# WARNING! All changes made in this file will be lost!
This makes it quite clear that the file is not meant to be edited. But this is not a problem, because it is just an ordinary python module, and so it's easy enough to import it into your main application and access it from there.
All you need to do is create a subclass of the top-level object from Qt Designer (which will be a QMainWindow
, QDialog
or QWidget
), and then use the setupUi
method provided by the generated module to add all of the widgets to an instance of that subclass.
So if the top-level object from Qt Designer was named "MainWindow", pyuic will create a corresponding Ui_MainWindow
class that can be imported into a main.py
script and used something like this:
from PyQt4 import QtCore, QtGui
from myui import Ui_MainWindow
class Window(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.button.clicked.connect(self.handleButton)
def handleButton(self):
print('Hello World!')
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
See Using Qt Designer in the PyQt Documentation for more details.