如果它使用信号,我无法弄清楚如何从函数返回值。这是一些代码:
class MyWindow(QtWidgets.QWidget):
def __init__(self, *args, **kwargs):
super(MyWindow, self).__init__(*args, **kwargs)
self.txt_input = QtWidgets.QLineEdit()
self.btn_submit = QtWidgets.QPushButton('&Отправить')
self.vbox = QtWidgets.QVBoxLayout()
self.vbox.addWidget(self.txt_input)
self.vbox.addWidget(self.btn_submit)
self.setLayout(self.vbox)
class MyClass(QtCore.QObject):
validated = QtCore.pyqtSignal()
def __init__(self, window, *args, **kwargs)
self.window = window
self.arg = None
def get_value(arg):
self.arg = arg
if arg == 0:
self.window.btn_submit.connect(check_value)
self.window.show()
def check_value():
self.window.hide()
if window.txt_input.text == 'banana':
self.validated.emit()
if __name__ == "__main__":
window = MyWindow()
my_obj = MyClass(window)
result = my_obj.get_value(0)
当然,get_value()
调用将返回 None。我想知道如何同步这段代码,所以在函数中get_value()
我可以等待信号然后返回一些东西。