我试图在不使用函数的情况下获取Qthread类的signal发出的值
当用户选择退出并按GUI上的[X]按钮时,我正在调用警报框,因此我通过线程方式调用此警报框,以确保我的GUI不会冻结。
以下是相关代码:
class ABC:
def __init__(self):
self.close = CloseThread() # Creating instance of QThread Class
........
........
........
def closeEvent(self, event):
button = self.close.CloseResult
self.close.start()
if button == 1:
event.accept()
else:
event.ignore()
class CloseThread(QThread):
"""Threading class which is emitting the return value according to the choice
of the user(When the message appears, if the user chooses
'Ok' then return value is 1 and if the user chooses
'Cancel'return value is 2)"""
CloseResult = QtCore.pyqtSignal(object)
def __init__(self):
QThread.__init__(self)
def close(self):
button = win32api.MessageBox(0, 'Do you want to Exit?', 'Message')
self.CloseResult.emit(button)
def run(self):
self.close()
我知道我可以通过self.close.CloseResult.connect(self.fn_name)
而不是使用self.close.CloseResult
来获得发出的值,但是我不想调用另一个函数,因为我在这里扩展了closeEvent
函数的作用域,所以我不想调用另一个函数(实际上,通过调用另一个函数,事情并没有按预期的那样运行)
Note: By using
self.close.CLoseResult
I am getting an object so is there any way to access this object's value or not?
那么,有没有什么方法可以在不调用任何其他函数的情况下,只在变量中获取发出的值呢?在
目前没有回答
相关问题 更多 >
编程相关推荐