PyQt5: chapter1-show welcome message

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 ()
  1. Normal
  2. NoEcho
  3. Password
  4. PasswordEchoOnEdit
  • maxLength()
  • setText()
  • text()
  • clear()
  • setReadOnly()
  • isReadOnly()
  • setEnabled ()
  • setFocus()

QPushButton class

  • setText()
  • setIcon ()

Create an instance

  1. Create a window based on the Dialog without Buttons template
  2. Drag the Label widget from the Display Widgets directory and set the text property to Enter your name
  3. Drag out a Label component again and set the objectName attribute to labelResponse
  4. Drag the Line Edit widget from the Input Widgets directory and set the objectName property to lineEditName
  5. Drag the Push Button component from the Buttons directory, set the text property to Click, and set its objectName property to ButtonClickMe
  6. Save as demoLineEdit.ui file
  7. Use pyuic5 to generate demoLineEdit.py file
  8. 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())

 

Published 120 original articles · won praise 3 · Views 3746

Guess you like

Origin blog.csdn.net/weixin_43307431/article/details/105616695
Recommended