简体   繁体   English

无法在python中打印LineEdit值

[英]Can't print a LineEdit value in python

在此处输入图片说明

在此处输入图片说明

class Ui_Form(QtWidgets.QWidget):

def __init__(self):

    super(self.__class__, self).__init__()
    self.setupUi(self)


def setupUi(self, Form):
    Form.setObjectName("Form")
    Form.resize(410, 325)
    font = QtGui.QFont()
    font.setBold(True)
    font.setUnderline(False)
    font.setWeight(75)
    Form.setFont(font)
    self.gridLayout = QtWidgets.QGridLayout(Form)
    self.gridLayout.setObjectName("gridLayout")
    self.verticalLayout = QtWidgets.QVBoxLayout()
    self.verticalLayout.setObjectName("verticalLayout")
    self.label = QtWidgets.QLabel(Form)
    font = QtGui.QFont()
    font.setPointSize(12)
    self.label.setFont(font)
    self.label.setObjectName("label")
    self.verticalLayout.addWidget(self.label)
    self.label_4 = QtWidgets.QLabel(Form)
    self.label_4.setObjectName("label_4")
    self.verticalLayout.addWidget(self.label_4)
    self.lineEdit_2 = QtWidgets.QLineEdit(Form)
    self.lineEdit_2.setObjectName("lineEdit_2")
    self.verticalLayout.addWidget(self.lineEdit_2)
    self.label_5 = QtWidgets.QLabel(Form)
    self.label_5.setObjectName("label_5")
    self.verticalLayout.addWidget(self.label_5)
    self.lineEdit = QtWidgets.QLineEdit(Form)
    self.lineEdit.setObjectName("lineEdit")
    self.verticalLayout.addWidget(self.lineEdit)     
    spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
    self.verticalLayout.addItem(spacerItem)
    self.horizontalLayout = QtWidgets.QHBoxLayout()
    self.horizontalLayout.setObjectName("horizontalLayout")
    self.pushButton_2 = QtWidgets.QPushButton(Form)
    self.pushButton_2.setObjectName("pushButton_2")
    self.horizontalLayout.addWidget(self.pushButton_2)
    self.pushButton = QtWidgets.QPushButton(Form)
    self.pushButton.setObjectName("pushButton")
    self.horizontalLayout.addWidget(self.pushButton)
    self.verticalLayout.addLayout(self.horizontalLayout)
    self.progressBar = QtWidgets.QProgressBar(Form)
    self.progressBar.setProperty("value", 0)
    self.progressBar.setObjectName("progressBar")
    self.verticalLayout.addWidget(self.progressBar)
    self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)

    self.pushButton_2.clicked.connect(self.Entrar)
    self.pushButton.clicked.connect(self.Cadastrar)


    self.retranslateUi(Form)
    QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
    _translate = QtCore.QCoreApplication.translate
    Form.setWindowTitle(_translate("Form", "Gerenciador de Ordem de Serviço"))
    self.label.setText(_translate("Form", "Faça login ou cadastre-se"))
    self.label_4.setText(_translate("Form", "Login:"))
    self.label_5.setText(_translate("Form", "Senha:"))
    self.pushButton_2.setText(_translate("Form", "Entrar"))
    self.pushButton.setText(_translate("Form", "Cadastrar"))


def Entrar(self): #aqui faz a busca dos dados de cadastro, se corretos e cadastrados vai para programa principal
        log = self.lineEdit.text()
        passw = self.lineEdit_2.text()
        logqry = 'SELECT NomeUsu FROM registro WHERE NomeUsu ='  + "\""+ log +"\""
        passqry = 'SELECT SenhaProg FROM registro WHERE SenhaProg =' + "\"" + passw + "\""
        print(self.lineEdit.text())
        print(log)
        print(passw)
        print(logqry)
        print(passqry)

Hi, I have this part of my code, is that a gui, and a did a method that it's supposed to print the value of the LineEdit and LineEdit_2 value, but when I run the event the , that don't show nothing, like the lineEdit was empty. 嗨,我的代码部分是gui,并且做了一个应该打印LineEdit和LineEdit_2值的方法,但是当我运行事件时,它什么也不显示,例如lineEdit为空。

Can anyone help?? 有人可以帮忙吗? Sorry about any gramatical mistake. 对不起任何语法错误。

log and passw are not ordinary Python strings, they're QString s, so to print them you have to convert them to strings first. logpassw不是普通的Python字符串,它们是QString ,因此要打印它们,必须先将它们转换为字符串。

log = str(self.lineEdit.text())
passw = str(self.lineEdit_2.text())

Or, If you want them to be QString s, print them as follows 或者,如果希望它们成为QStringQString如下所示打印它们

print("%s\n%s" % log,passw)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM