Pycharm: Python Qt code code completion

后端 未结 2 1234
梦谈多话
梦谈多话 2021-01-14 04:47

I am a beginner with Qt in Python.

I create simple from using Qt Designer.

\"enter

2条回答
  •  执念已碎
    2021-01-14 05:04

    1) generate python code: pyuic4 -o mygui.py mygui.ui

    2) write code:

    import sys
    from PyQt4 import QtCore, QtGui
    from mygui import Ui_MainWindow
    
    class StartQT4(QtGui.QMainWindow):
        def __init__(self, parent=None):
            QtGui.QWidget.__init__(self, parent)
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.abc)
    
        def abc(self):
            input = self.ui.lineEdit.text()
            self.ui.label_2.setText(input)
    
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = StartQT4()
        myapp.show()
        sys.exit(app.exec_())
    

    It works, but is possible to write QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.abc) simpler?

提交回复
热议问题