1

I have created a GUI application in python using PyQt5.

The steps are first I have created a ui file in Qt Designer. Then I converted that ui file into a py file using pyuic4 -o demo.ui -x demo.py in a terminal. After that I modify the py file to get dynamic values from a database. But when I have a little change in design, again I am creating the ui file, and again coverting to a py file and writing the code for the database.

So it takes a lot of time to repeat the same process. Are there any options for converting a py file to a ui file? Or any other suggestions?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
user3386599
  • 45
  • 2
  • 8

2 Answers2

1

You can load the .ui file in your python script using the following command :

loadUi('demo.ui', self)

There is some related examples in the folder named 'pyuic' of pyqt examples.

reno-
  • 325
  • 2
  • 10
  • Thanks for replying .I can load ui file in python script.But is it possible to retrive database values in ui file? – user3386599 Mar 18 '16 at 11:46
  • I suggest you create a new question dedicated to your need with your code and a description of your problem – reno- Mar 21 '16 at 16:55
1

You should never modify the modules generated by pyuic. They are meant to be static modules that are imported into your main application.

The ui module should be created like this:

pyuic5 -o mainwindwow.py mainwindow.ui

And the main application file should look like this:

import sys
from PyQt5 import QtWidgets
from mainwindow import Ui_MainWindow

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.closeButton.clicked.connect(self.close)

if __name__ == '__main__':

    import sys
    app = QtWidgets.QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())

Further information can be found in the PyQt5 docs - see Using Qt Designer.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336