[Python] Qdialog error in Python module - Unbound method QDialog.exec() needs an argument

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    In python I am attempting to execute a Qdialog. I get the error message in the heading but am not sure what it is telling me is wrong and therefore how to fix it.

    The dialog execution code is

    dlg = CCDialog
    result = dlg.exec()


    CCDialog is imported using

    from cust_code_dialog import CCDialog


    The code for cust_code_dialog is below

    import os

    from Windows.ui_cust_code import Ui_Dialog
    # This imports (loads) the class Ui_Dialog out of the module cust_dialog.py
    # which is the code saved out of QTdesigner
    # for the module cust_code.ui which is a window dialog

    from PySide6.QtWidgets import (
    QDialog,
    QDialogButtonBox,
    )

    basedir = os.path.dirname(__file__)

    class CCDialog(Ui_Dialog, QDialog):
    #sets up a class to execute in order to present dialog window imported previously
    print("In CCDialogue")
    def __init__(self, parent=None):
    super().__init__(parent)
    print("In def init")
    self.setupUi(self)
    self.cc_input.editingFinished.connect(self.check_disable)
    self.buttonBox.accepted.connect(self.maybe_accept)
    self.buttonBox.rejected.connect(self.reject)

    def maybe_accept(self):
    print("In maybe_accept")
    if self.validate():
    self.accept()

    def check_disable(self):
    print("In check_disable")
    btn = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok)
    is_valid = self.validate()
    btn.setEnabled(is_valid)

    def validate(self):
    print("In validate")
    customer_code = self.cc_input.text() # Updating the customer code
    if len(customer_code) != 6:
    self.cc_error.setText("Customer Code Must Be 6 Characters")
    self.cc_error.setStyleSheet("background-color : red; color : white")
    return False
    self.cc_error.setStyleSheet("")
    self.cc_error.setText("")
    return True


    Thanks in advance for your help.

    Continue reading...

Compartilhe esta Página