Python_PyQt_ basic use

Manual connection signals and slots:

In the back of automatically generated UI file, right-click, select the third item: Generate, how will create a form, like the default, then select the signal you want to create, provided that prior to remember the name of the control, then down will generate a file, his import module may be a problem, note the imported package, the file may be automatically imported more than one. You need to delete manually add down the need to import

from PyQt5 import QtWidgets

For example behind the window:

if  __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    ui = MainWindow()
    ui.show()
    sys.exit(app.exec())

Since the groove to define added, can be introduced into the space defined inside the function

# - * - Coding: UTF-. 8 - * - 

"" " 
. This code can not be performed separately, because of the absence of the required UI.first 
for reference
" "" from PyQt5 Import QtWidgets from PyQt5.QtCore Import pyqtSlot from PyQt5.QtWidgets Import The QMainWindow from Ui_first Import Ui_MainWindow class the MainWindow (The QMainWindow, Ui_MainWindow): "" " . class Documentation goes here Wallpaper " "" DEF the __init__ (Self, parent = None): "" " Constructor @param parent reference to the parent widget QWidget @type """ . Super (MainWindow, Self) __init__ (parent) self.setupUi (Self) @pyqtSlot () DEF on_pushButton_5_clicked (Self): "" " . It is clear the input box " "" self.lineEdit.setText ( "" ) @pyqtSlot () DEF on_pushButton_4_clicked (Self): "" " this is the content of the input box print " "" # TODO: not yet Implemented the Print (self.lineEdit.text ()) IF __name__ == " __main__ " : import sys app = QtWidgets.QApplication(sys.argv) ui = MainWindow() ui.show() sys.exit(app.exec())

Guess you like

Origin www.cnblogs.com/Alom/p/12114700.html