Linking a qtDesigner .ui file to python/pyqt?

前端 未结 12 1412
北海茫月
北海茫月 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 02:08

    You can also use uic in PyQt5 with the following code.

    from PyQt5 import uic, QtWidgets
    import sys
    
    class Ui(QtWidgets.QDialog):
        def __init__(self):
            super(Ui, self).__init__()
            uic.loadUi('SomeUi.ui', self)
            self.show()
    
    if __name__ == '__main__':
        app = QtWidgets.QApplication(sys.argv)
        window = Ui()
        sys.exit(app.exec_())
    

提交回复
热议问题