Window template
- Dialog with Buttons Bottom: This template creates a form with OK and Cancel buttons in the lower right of the form
- Dialog with Buttons Right: This template creates a form with OK and Cancel buttons in the upper right of the form
- Dialog without Buttons: This template creates an empty form on which you can place widgets. The dialog's superclass is QDialog
- Main Window: This template provides a main application window, which contains a menu bar and a toolbar, if you do not need it, you can delete it
- Widget: This template creates a form whose superclass is QWidget instead of QDialog.
QLabel class
- setText (): Specify content
- setPixmap (): an instance of the QPixmap class, specifying pixel mapping
- setNum (): Integer value or floating point value of the specified window
- clear (): clear the window content
QLineEdit class
- setEchoMode ()
- Normal
- NoEcho
- Password
- PasswordEchoOnEdit
- maxLength()
- setText()
- text()
- clear()
- setReadOnly()
- isReadOnly()
- setEnabled ()
- setFocus()
QPushButton class
- setText()
- setIcon ()
Create an instance
- Create a window based on the Dialog without Buttons template
- Drag the Label widget from the Display Widgets directory and set the text property to Enter your name
- Drag out a Label component again and set the objectName attribute to labelResponse
- Drag the Line Edit widget from the Input Widgets directory and set the objectName property to lineEditName
- Drag the Push Button component from the Buttons directory, set the text property to Click, and set its objectName property to ButtonClickMe
- Save as demoLineEdit.ui file
- Use pyuic5 to generate demoLineEdit.py file
- Create callLineEdit.py file, call demoLineEdit.py file, the code is as follows
callLineEdit.py
import sys
from PyQt5.QtWidgets import QDialog,QApplication
from cookbook_200419.demoLineEdit import *
class MyForm(QDialog):
def __init__(self):
super().__init__()
self.ui=Ui_Dialog()
self.ui.setupUi(self)
self.ui.ButtonClickMe.clicked.connect(self.dispmessage)
self.show()
def dispmessage(self):
self.ui.labelResponse.setText("Hello "+self.ui.lineEditName.text())
if __name__=="__main__":
app=QApplication(sys.argv)
w=MyForm()
w.show()
sys.exit(app.exec())