PyQt5系列文章
效果图
完整代码
import sys
from PyQt5.QtWidgets import QLabel,QLineEdit,QFormLayout,QWidget,QApplication,QMainWindow
class QFormLayoutDemo(QMainWindow):
def __init__(self):
super(QFormLayoutDemo, self).__init__()
#设置窗口大小
self.resize(400, 150)
#设置窗口标题
self.setWindowTitle("QFormLayoutDemo")
layout = QFormLayout()
label1 = QLabel("姓名")
lineEdit1 = QLineEdit()
label2 = QLabel("职务")
lineEdit2 = QLineEdit()
layout.addRow(label1, lineEdit1)
layout.addRow(label2, lineEdit2)
mainFrame = QWidget()
mainFrame.setLayout(layout)
self.setCentralWidget(mainFrame)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QFormLayoutDemo()
main.show()
sys.exit(app.exec_())