• pyqt5实现注册界面并获得文本框内容


    获取框里面的内容,有一个BUG,搞了好久才搞定。


    __author__ = 'ayew'
    import sys
    from PyQt5.QtCore import*
    from PyQt5.QtWidgets import QWidget, QApplication, QGroupBox, QPushButton, QLabel, QHBoxLayout, QVBoxLayout, QGridLayout, QFormLayout, QLineEdit, QTextEdit


    class login(QWidget):
    def __init__(self):
    super(login,self).__init__()
    self.initUi()

    def initUi(self):
    self.setWindowTitle("login")
    layout = QGridLayout()
    self.setGeometry(600, 600, 400, 400)


    nameLabel = QLabel("姓名")
    self.nameLineEdit = QLineEdit(" ")
    sexLabel = QLabel("性别")
    self.sexLineEdit = QLineEdit(" ")
    emitLabel = QLabel("手机号")
    self.phoneLineEdit = QLineEdit("")
    timeLabel = QLabel("邮箱")
    self.mailEdit = QLineEdit("")
    # layout.setSpacing(10)
    layout.addWidget(nameLabel,1,0)
    layout.addWidget(self.nameLineEdit,1,1)
    layout.addWidget(sexLabel, 2, 0)
    layout.addWidget(self.sexLineEdit, 2, 1)
    layout.addWidget(emitLabel,3,0)
    layout.addWidget(self.phoneLineEdit,3,1)
    layout.addWidget(timeLabel,4,0)
    layout.addWidget(self.mailEdit,4,1)
    layout.setColumnStretch(1, 10)
    save_Btn = QPushButton('保存')
    cancle_Btn = QPushButton('取消')
    cancle_Btn.clicked.connect(QCoreApplication.quit)
    save_Btn.clicked.connect(self.addNum)
    layout.addWidget(save_Btn)
    layout.addWidget(cancle_Btn)
    self.setLayout(layout)

    def addNum(self):
    name = self.nameLineEdit.text() # 获取文本框内容
    sex = self.sexLineEdit.text()
    phone = self.phoneLineEdit.text()
    mail = self.mailEdit.text()
    print('姓名: %s 性别: %s 手机号: %s 邮箱: %s ' % (name,
    sex, phone, mail))
  • 相关阅读:
    JavaScript学习——使用JS实现首页轮播图效果
    JavaScript学习——使用JS完成注册页面表单校验
    JavaScript基础
    HTML&CSS——使用DIV和CSS完成网站首页重构
    HTML&CSS——网站注册页面
    java ------------ 集合(四) Collections类
    Java ---------- 集合(三) Map接口
    java ---------- 集合(二) Set 接口和Iterator 接口
    Java ---------- 集合
    idea -------- 常用快捷键
  • 原文地址:https://www.cnblogs.com/ansang/p/7895075.html
Copyright © 2020-2023  润新知