窗口模板
- Dialog with Buttons Bottom:此模板创建一个表单,表单右下方中有OK和Cancel按钮
- Dialog with Buttons Right:此模板创建一个表单,表单右上方中有OK和Cancel按钮
- Dialog without Buttons:此模板创建一个空表单,您可以在其上放置小部件。对话框的超类是QDialog
- Main Window:此模板提供一个主应用程序窗口,其中包含一个菜单栏和一个工具栏,如果不需要,可以将其删除
- Widget:这个模板创建一个超类是QWidget而不是QDialog的表单。
QLabel类
- setText():指定内容
- setPixmap():QPixmap类的实例,指定像素映射
- setNum():指定窗口的整数值或浮点值
- clear():清除窗口内容
QLineEdit类
- setEchoMode()
- Normal
- NoEcho
- Password
- PasswordEchoOnEdit
- maxLength()
- setText()
- text()
- clear()
- setReadOnly()
- isReadOnly()
- setEnabled()
- setFocus()
QPushButton 类
- setText()
- setIcon()
创建实例
- 创建基于Dialog without Buttons模板的窗口
- 从Display Widgets目录中拖出Label部件,设定text属性为Enter your name
- 再次拖出一个Label部件,设定objectName属性为labelResponse
- 从Input Widgets目录中拖出Line Edit部件,设定objectName属性为lineEditName
- 从Buttons目录中拖出Push Button部件,设定text属性为Click,设定其objectName属性为ButtonClickMe
- 保存为demoLineEdit.ui文件
- 使用pyuic5生成demoLineEdit.py文件
- 创建callLineEdit.py文件,调用demoLineEdit.py文件,代码如下
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())