Python Forum
PyQT5 : Unable to Create Another Dialog While One is Open
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQT5 : Unable to Create Another Dialog While One is Open
#1
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.


# -*- 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
Reply


Messages In This Thread
PyQT5 : Unable to Create Another Dialog While One is Open - by iMuny - Jul-03-2019, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How a QMainWindow can open a dialog? panoss 4 3,581 Feb-03-2022, 04:33 PM
Last Post: panoss
  How can I create a new tag with PyQt5? nickzsche 2 1,497 Jan-12-2022, 06:10 PM
Last Post: Axel_Erfurt
  [Tkinter] question for a tkinter dialog box RobertAlvarez424 2 2,269 Aug-25-2021, 03:08 PM
Last Post: RobertAlvarez424
  [Tkinter] cancelling open dialog gives empty string rwahdan 2 3,408 Jul-17-2021, 09:17 PM
Last Post: steve_shambles
  Unable to install PyQt5 using pip. edwin4project 2 3,400 Nov-06-2020, 06:53 PM
Last Post: Larz60+
  [WxPython] Return code when closing the dialog ioprst 1 3,208 Aug-13-2019, 11:47 AM
Last Post: jefsummers
  [Tkinter] Unable to create checkbox and select at run time tej7gandhi 5 4,686 May-05-2019, 04:57 PM
Last Post: tej7gandhi
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,839 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  [WxPython] Any dialog that allow user to select file OR folder? buran 3 4,265 Apr-03-2019, 06:33 PM
Last Post: Yoriz
  [PyQt] I get the error when I try to open the sample Why can pyqt5 installed onatdogan 3 3,102 Dec-25-2018, 03:00 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020