Z
Z
zaordu2021-04-01 17:35:34
Python
zaordu, 2021-04-01 17:35:34

How to read lineEdit data (python)?

I can’t read the data from the lineEdit into which the login is entered and compared with the data from the database query
when I didn’t use the database, but just compared it with a variable, it worked, I don’t understand how. I chose the most inefficient method of learning PyQT - by clicking, don't hit
And yes, if it's not difficult, you can still explain when exactly to use self - I seem to understand its essence, but when exactly to indicate it causes problems. Directly for a ram it is desirable: D
Thanks in advance!

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql.cursors
from main1open import Windowone
from main2open import Windowtwo
import mysql.connector
from mysql.connector import MySQLConnection, Error
connection = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password='adminadmin',
                             db='mydb',
                             charset='utf8mb4',)
print("connected!!!")

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(400, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(130, 360, 131, 41))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(130, 410, 131, 41))
        self.pushButton_2.setObjectName("pushButton_2")
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(50, 179, 281, 31))
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(50, 260, 281, 31))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(50, 230, 111, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(50, 150, 91, 31))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "log in"))
        self.pushButton_2.setText(_translate("MainWindow", "create an account"))
        self.label.setText(_translate("MainWindow", "password"))
        self.label_2.setText(_translate("MainWindow", "Login"))


class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton.clicked.connect(self.onClicked)
        self.exampleApp = Windowone()

        self.pushButton_2.clicked.connect(self.onClicked1)
        self.exampleApp_2 = Windowtwo()                         # exampleApp_2

    def onClicked(self):
        with connection:
            self.curs = connection.cursor()
            self.curs.execute("SELECT username FROM клиент")
            rows = self.curs.fetchall()# выполнение запроса
            res = (self.lineEdit.toPlainText(),)
            print(rows)
            for row in rows:
                print(rows)
                if row == res:
                    self.exampleApp.show()
                break
                else:
                    print("неправильный логин")



    def onClicked1(self):
        self.exampleApp_2.show()                             # exampleApp_2




if __name__=="__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = ExampleApp()
    window.show()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question