/tmp/snapshot-pyside-6.3/pyside-setup/examples/widgets/state-machine/twowaybutton#

(You can also check this code in the repository)

import sys

from PySide6.QtWidgets import QApplication, QPushButton
from PySide6.QtStateMachine import QState, QStateMachine


if __name__ == '__main__':
    app = QApplication(sys.argv)
    button = QPushButton()
    machine = QStateMachine()

    off = QState()
    off.assignProperty(button, 'text', 'Off')
    off.setObjectName('off')

    on = QState()
    on.setObjectName('on')
    on.assignProperty(button, 'text', 'On')

    off.addTransition(button.clicked, on)
    on.addTransition(button.clicked, off)

    machine.addState(off)
    machine.addState(on)
    machine.setInitialState(off)
    machine.start()
    button.resize(100, 50)
    button.show()
    sys.exit(app.exec())