取决于条件 我想把一个纽子连接起来,与另一个功能连接起来。
我要说的是:
myButton = QtGui.QPushButton()
例如,我要说,如果存在互联网联系,我会检查。
if connected == True:
myButton.clicked.connect(function_A)
elif connected == False:
myButton.clicked.connect(function_B)
First of all I would like to disconnect a button from any function it was already connected before the button is being re-assigned/re-connected to another function (function_A or function_B). Secondly, I have already noticed that after the button is re-connected it takes an extra click for the button to pick up a new function. After the button is re-connected to another function it still attempts to run a previous function - a function to which a button was connected earlier (before a re-connection). Please advice. Thanks in advance!
EDITED LATER:
这种方法似乎是一种植被()。 脱节()方法可用于将丁子与其相关的功能分离。
myButton.disconnect()
Unfortunately .disconnect() throws an error if a widget is not connected to any function. To get around it I am using Try/Except. But I would rather use a more elegant solution...
try: myButton.clicked.disconnect()
except Exception: pass