mardi 14 août 2018

Python PyQt5 - how show QMessageBox conditionally (if statements)

I would like the GUI to eject messages based on logic results. I would like something like that:

class App(QWidget):

def __init__(self):
    super().__init__()
    self.title = 'PyQt5'
    self.initUI()

def initUI(self):
    self.setWindowTitle(self.title)
    self.setGeometry(100, 100, 100, 100)
    ....

    if char == "A":
       self.giveMeMessage(char)

    if char == "B":
       self.giveMeMessage(char)

    self.show()

def giveMeMessage(self, char):
    QMessageBox.warning(self, 'Message', "Char is: " + char, QMessageBox.Ok, QMessageBox.Ok)

(Char comes out of logic.)
What am I doing wrong? Where it should be if statement? Missing a decorator? Static | dynamic?

Aucun commentaire:

Enregistrer un commentaire