datetime:2019/5/20 16:12
author:nzb
行编辑
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QDialog, QVBoxLayout, QLabel, QGroupBox, QCheckBox, QHBoxLayout, QPushButton, QLineEdit
from PyQt5 import QtGui, QtCore
class UI_demo(QWidget):
"""用户界面"""
def __init__(self):
super().__init__()
self.title = 'PyQt5 Lineedit'
self.left = 600
self.top = 200
self.width = 500
self.height = 200
self.initWindow()
def initWindow(self):
self.setWindowIcon(QtGui.QIcon('../img/home.ico'))
self.setGeometry(self.left, self.top, self.width, self.height)
self.setWindowTitle(self.title)
hbox = QHBoxLayout()
self.lineedit = QLineEdit(self)
self.lineedit.setFont(QtGui.QFont('Sanserif', 15))
self.lineedit.returnPressed.connect(self.onPressed)
hbox.addWidget(self.lineedit)
self.lable = QLabel(self)
self.lable.setFont(QtGui.QFont('Sanserif', 15))
hbox.addWidget(self.lable)
self.setLayout(hbox)
self.show()
def onPressed(self):
"""输入绑定事件"""
self.lable.setText(self.lineedit.text())
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = UI_demo()
sys.exit(app.exec_())