PyQt Widget connect() and disconnect()

前端 未结 2 1044
时光说笑
时光说笑 2020-12-24 02:53

Depending on a conditions I would like to connect/re-connect a button to a different function.

Let\'s say I have a button:

myButton = QtGui.QPushButt         


        
2条回答
  •  不思量自难忘°
    2020-12-24 03:34

    Try this:

    from PyQt4 import QtGui as gui
    
    app = gui.QApplication([])
    
    myButton = gui.QPushButton()
    
    def function_A():
        myButton.clicked.disconnect() #this disconnect all!
        myButton.clicked.connect(function_B)
        print 'function_A'
    
    def function_B():
        myButton.clicked.disconnect(function_B) #this disconnect function_B
        myButton.clicked.connect(function_A)
        print 'function_B'
    
    myButton.clicked.connect(function_A)
    myButton.setText("Click me!")
    myButton.show()
    
    app.exec_()
    

提交回复
热议问题