Linking a qtDesigner .ui file to python/pyqt?

前端 未结 12 1329
北海茫月
北海茫月 2020-11-28 01:33

So if I go into QtDesigner and build a UI, it\'ll be saved as a .ui file. How can I make this as a python file or use this in python?

相关标签:
12条回答
  • 2020-11-28 01:46

    You can convert your .ui files to an executable python file using the below command..

    pyuic4 -x form1.ui > form1.py
    

    Now you can straightaway execute the python file as

    python3(whatever version) form1.py
    

    You can import this file and you can use it.

    0 讨论(0)
  • 2020-11-28 01:48

    In order to compile .ui files to .py files, I did:

    python pyuic.py form1.ui > form1.py
    

    Att.

    0 讨论(0)
  • 2020-11-28 01:52

    You need to generate a python file from your ui file with the pyuic tool (site-packages\pyqt4\bin)

    pyuic form1.ui > form1.py
    

    with pyqt4

    pyuic4.bat form1.ui > form1.py
    

    Then you can import the form1 into your script.

    0 讨论(0)
  • 2020-11-28 01:53

    in pyqt5 to convert from a ui file to .py file

    pyuic5.exe youruifile.ui -o outputpyfile.py -x

    0 讨论(0)
  • 2020-11-28 01:55

    you can compile the ui files like this

    pyuic4 -x helloworld.ui -o helloworld.py
    
    0 讨论(0)
  • 2020-11-28 01:58

    Combining Max's answer and Shriramana Sharma's mailing list post, I built a small working example for loading a mywindow.ui file containing a QMainWindow (so just choose to create a Main Window in Qt Designer's File-New dialog).

    This is the code that loads it:

    import sys
    from PyQt4 import QtGui, uic
    
    class MyWindow(QtGui.QMainWindow):
        def __init__(self):
            super(MyWindow, self).__init__()
            uic.loadUi('mywindow.ui', self)
            self.show()
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        window = MyWindow()
        sys.exit(app.exec_())
    
    0 讨论(0)
提交回复
热议问题