How do you get information from the dialogue window?
-
Good day, everyone.
How do we get the dialogue window back?
I'm doing this right now:
def build_exel_registration(self): info = ExelInfo() # Создаю экземпляр диалогового окна info.exec() # Ставлю этот скрипт на паузу (Не понимаю как это работает) if info.ok: # Смотрю переменную диалогового окна, проверяя нажал кнопку ok или cancel name = info.name.text() # Беру имя из строки ввода
Класс диалогового окна
class ExelInfo(QDialog, exel_info_class):
def init(self, *args):
super(ExelInfo, self).init()
self.setupUi(self)
self.setModal(True)
self.setWindowIcon(QIcon(getcwd() + "/images/icon.ico"))
self.show()def accept(self): # Если нажата кнопка Ok
self.ok = True
self.close()def rect(self): # Если нажата кнопка cancel
self.ok = False
self.close()
But I wish it was human.
For example, a dialogue window would return the name immediately, for example:name = ExelInfo()
Can we do that?
'Cause QMessageBox works like that!
-
> name = ExelInfo()
Can we do that?
'Cause QMessageBox works like that!
You can't do that. But you can.
QMessageBox
Make a statistical method and from it generate dialogue and dialogue, for example:class ExelInfo(QDialog, exel_info_class):
# ... @staticmethod def get_name(): info = ExelInfo() info.exec() if info.ok: return info.name.text()
And use:
name = ExelInfo.get_name()