Pyqt5 and buttons that lock

Asked

Viewed 155 times

-2

I made a basic Pyqt5 application with login and registration. The problem is that when I click on any button to perform any action be it, save next or login, Python stops working. I’ve searched everywhere, but I can’t find anything on the problem.

Follow the implemented code:

from PyQt5 import QtCore, QtGui, QtWidgets
import sqlite3

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
    return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def insertData(self):
        username = self.uname_lineEdit.text()
        email = self.email_lineEdit.text()
        password = self.password_lineEdit.text()

        connection  = sqlite3.connect("login.db")
        connection.execute("INSERT INTO USERS VALUES(?,?,?)",(username,email,password))
        connection.commit()
        connection.close()

    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(305, 341)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("Icon/key.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Dialog.setWindowIcon(icon)
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(60, 93, 111, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(60, 190, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.uname_lineEdit = QtWidgets.QLineEdit(Dialog)
        self.uname_lineEdit.setGeometry(QtCore.QRect(130, 100, 141, 20))
        self.uname_lineEdit.setObjectName("uname_lineEdit")
        self.password_lineEdit = QtWidgets.QLineEdit(Dialog)
        self.password_lineEdit.setGeometry(QtCore.QRect(130, 200, 141, 21))
        self.password_lineEdit.setObjectName("password_lineEdit")
        self.signup_btn = QtWidgets.QPushButton(Dialog)
        self.signup_btn.setGeometry(QtCore.QRect(120, 290, 75, 23))
        self.signup_btn.setObjectName("signup_btn")
        self.signup_btn.clicked.connect(self.insertData)
        self.label_4 = QtWidgets.QLabel(Dialog)
        self.label_4.setGeometry(QtCore.QRect(0, 0, 321, 81))
        font = QtGui.QFont()
        font.setPointSize(18)
        self.label_4.setFont(font)
        self.label_4.setAlignment(QtCore.Qt.AlignCenter)
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(Dialog)
        self.label_5.setGeometry(QtCore.QRect(30, 144, 81, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.uname_lineEdit_2 = QtWidgets.QLineEdit(Dialog)
        self.uname_lineEdit_2.setGeometry(QtCore.QRect(130, 150, 141, 20))
        self.uname_lineEdit_2.setObjectName("uname_lineEdit_2")
        self.label_3 = QtWidgets.QLabel(Dialog)
        self.label_3.setGeometry(QtCore.QRect(60, 240, 61, 31))
        font = QtGui.QFont()
        font.setPointSize(10)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.comboBox = QtWidgets.QComboBox(Dialog)
        self.comboBox.setGeometry(QtCore.QRect(130, 245, 141, 21))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.label_6 = QtWidgets.QLabel(Dialog)
        self.label_6.setGeometry(QtCore.QRect(-90, -40, 611, 431))
        self.label_6.setStyleSheet("background-color: rgb(149, 149, 149);\n" "background-color: rgb(207, 207, 207);")
        self.label_6.setText("")
        self.label_6.setObjectName("label_6")
        self.label_6.raise_()
        self.label.raise_()
        self.label_2.raise_()
        self.uname_lineEdit.raise_()
        self.password_lineEdit.raise_()
        self.signup_btn.raise_()
        self.label_4.raise_()
        self.label_5.raise_()
        self.uname_lineEdit_2.raise_()
        self.label_3.raise_()
        self.comboBox.raise_()

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

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Cadastrar"))
        self.label.setText(_translate("Dialog", " Nome:"))
        self.label_2.setText(_translate("Dialog", "Senha:"))
        self.signup_btn.setText(_translate("Dialog", "Cadastrar"))
        self.label_4.setText(_translate("Dialog", "Criar Conta"))
        self.label_5.setText(_translate("Dialog", "Sobrenome:"))
        self.label_3.setText(_translate("Dialog", "Cargo:"))
        self.comboBox.setItemText(0, _translate("Dialog", "T.I"))
        self.comboBox.setItemText(1, _translate("Dialog", "Gerência"))
        self.comboBox.setItemText(2, _translate("Dialog", "Encarregado "))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
  • There is error in the code. Just scroll the screen you will see by color.

  • But I have already complicated all the screens separately and whenever I compile once it works and the ides do not accuse error (Pycharm, VS, IDLE),

  • So it copied and pasted wrong here. Look at this line: self.label_6.setStyleSheet("background-color: rgb(149, 149, 149);"background-color: rgb(207, 207, 207);"). There’s no way she’s right.

  • the correct line of the code is: self.label_6.setStyleSheet("background-color: rgb(149, 149, 149); n" "background-color: rgb(207, 207, 207);")

1 answer

0


The problem occurs because there is in the code a mixture of Pyqt4 and Pyqt5 which causes a Buffer Overflow which results in Python Crash

Browser other questions tagged

You are not signed in. Login or sign up in order to post.