0

Hello I have this red button:red button And I want it to change text to "+" after the first click I did it

from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtUiTools import QUiLoader
import sys


app = QApplication(sys.argv)
loader = QUiLoader()
window = loader.load("Strategion.ui", None)

class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        window.pushButton.clicked.connect(self.btt1)
    def btt1(self):
        self.sender().setText("+")
        if(self.sender().styleSheet() == 'background-color: rgb(0, 255, 0);font: 36pt "MS Shell" Dlg 2;'):
            self.sender().setStyleSheet('background-color: rgb(255, 0, 0);font: 36pt "MS Shell" Dlg 2;')
        else:
            self.sender().setStyleSheet('background-color: rgb(0, 255, 0);font: 36pt "MS Shell" Dlg 2;')
if __name__ == "__main__":
    start = MainWindow()
    window.show()
    app.exec()

and when i click the second time it should change the text, it shouldn't immediately change the text and color of the button at the same time, just the text first and then the color. Thank you in advance.

tajgel
  • 11
  • 4
  • Extend what you did [for your previous and very similar question](https://stackoverflow.com/q/75278037/2001654): use `if text != sometext:` `elif stylesheet != someStylesheet:` `else:`. Also, your usage of `MainWindow` (and the global reference to `window`) is completely wrong. If you want to "set up" a Designer UI in an existing widget, follow [this solution](https://stackoverflow.com/a/27610822) instead. – musicamante Jan 30 '23 at 14:14

0 Answers0