I have a class which inherits from QWidget.
Push button click is connected with some_function.
I would like to change PushButton color to red before function starts doing its core functionality and change it to green when the core will be finished, but i have no idea how to change PushButton color outside of some_button.
EDIT: I added button to the instance attributes as @dudakl suggested but color still changes after whole function finishing running, instead to red at the beginning and green at the end.
from PyQt5.QtWidgets import *
class AppWidget(QWidget):
def __init__(self, parent = None):
super(AppWidget, self).__init_(parent)
mainLayout = QGridLayout()
self.some_button()
mainLayout.addWidget(self.someButton)
self.setLayout(mainLayout)
self.show()
def some_button(self):
self.someButton = QGroupBox('Some GroupBox')
layout = QVBoxLayout()
button = QPushButton('Button')
button.clicked.connect(self.some_function)
layout.addWidget(button)
def some_function(self):
#change color to red
#do something
#change color to green