Jul-03-2019, 04:13 PM
Dear All
Hope you all are doing well. I've just recently ventured into the world of PyQt through online tuts etc. and it's feeling a bit overwhelming due to the huge resources available. I've started making a small application but am facing an issue where when i try to create a dialog box while one dialog box is already opened it doesn't open. The area where I'm facing the issue is commented in the code.
Regards
iMu
Hope you all are doing well. I've just recently ventured into the world of PyQt through online tuts etc. and it's feeling a bit overwhelming due to the huge resources available. I've started making a small application but am facing an issue where when i try to create a dialog box while one dialog box is already opened it doesn't open. The area where I'm facing the issue is commented in the code.
# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets
import mysql.connector
import sys
class MainApplication(QtWidgets.QWidget):
def __init__(self):
super(MainApplication, self).__init__()
self.setWindowTitle("Main Window")
loginstatus = self.get_login()
if loginstatus:
self.show()
def get_login(self):
login = LoginDlg()
if not login.exec_():
if login.OKID:
print("ID Found")
return True
class MsgBox(QtWidgets.QDialog):
def __init__(self, message, msgtitle):
super(MsgBox, self).__init__()
self.message = message
self.msgtitle = msgtitle
self.setupUI()
def setupUI(self):
messagebox = QtWidgets.QHBoxLayout()
messagebox.addStretch(1)
usermessage = QtWidgets.QLabel(self.message)
messagebox.addWidget(usermessage)
self.setWindowTitle(self.msgtitle)
self.setLayout(messagebox)
self.show()
class LoginDlg(QtWidgets.QDialog):
def __init__(self):
super(LoginDlg, self).__init__()
self.OKID = False
self.username = QtWidgets.QLineEdit()
self.password = QtWidgets.QLineEdit()
self.setupUI(self.username, self.password)
def setupUI(self, username, password):
entry_box = QtWidgets.QFormLayout()
entry_box.addRow("Username", username)
entry_box.addRow("Password", password)
button_box = QtWidgets.QHBoxLayout()
button_box.addStretch(1)
ok_button = QtWidgets.QPushButton("OK")
cancel_button = QtWidgets.QPushButton("Cancel")
button_box.addWidget(ok_button)
button_box.addWidget(cancel_button)
main_box = QtWidgets.QVBoxLayout()
main_box.stretch(1)
main_box.addLayout(entry_box)
main_box.addLayout(button_box)
self.setWindowTitle("Login")
self.setLayout(main_box)
ok_button.clicked.connect(self.ok_pressed)
cancel_button.clicked.connect(self.cancel_pressed)
def ok_pressed(self):
connection = mysql.connector.connect(host="192.168.0.168", user="LISTAPP", password="samba786")
cursor = connection.cursor()
cursor.execute("USE client_list;")
username = self.username.text()
password = self.password.text()
cursor.execute("SELECT * from auth;")
userData = [(each[1], each[2]) for each in cursor.fetchall()]
if (username, password) in userData:
self.close()
self.OKID = True
else:
# This window below does not open
errormsg = MsgBox("User ID not found", "Invalid data")
# This window above does not open
print("ID not found")
def cancel_pressed(self):
self.close()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
mainApplication = MainApplication()
sys.exit(app.exec_())Any help in the above regards would be highly appreciated.Regards
iMu
