# Introduction to Qt - demonstrating QPushButton
# by Anthony Vogelaar, Perth Scotland
# rev 0.10  2024-03-31  Initial release

import  os, sys, signal;    os.system('clear')
from    PySide6.QtWidgets   import  QApplication, QPushButton

# ================================== GUI =========================================

class GUI(QPushButton):

    def __init__(self):
        self.app   = QApplication([])
        self.color = None
        super().__init__()
        self.setWindowTitle('The Title')
        self.resize(200, 200)                       # size of label AND window
        self.setText('I am a QPushButton')
        self.setStyleSheet("font-weight: bold; color: blue")
        self.clicked.connect(self.onBtnClick)       # connect signal to slot
        self.show()


    # PushButton clicked slot
    def onBtnClick(self):
        self.color = 'green' if self.color == 'red' else 'red'
        self.setStyleSheet(f"background-color: {self.color}")

# ================================ Main ==========================================
        
signal.signal(signal.SIGINT, signal.SIG_DFL)        # handle ctrl-c
gui     = GUI()
sys.exit(gui.app.exec())

# ================================= End ==========================================
