I want to change the background color of my QLabel. On clicking the label, label connects to an event that sets the label color to Red and loop runs for 3 second after 3 seconds and completion on loops the color of label should change to Yellow
This is the code:
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QWidget,QDialog,QLabel
import sys
import time
def sleep4three():
for i in range(3):
print('inside the loop')
time.sleep(1)
class main(QDialog):
def __init__(self):
super(main,self).__init__()
loadUi('untitled.ui',self)
self.l.mousePressEvent = self.connect_
def connect_(self,event):
time.sleep(2)
ss = 'QLabel{background-color:red;}'
self.l.setStyleSheet(ss)
for i in range(3):
time.sleep(1)
self.l.setStyleSheet('QLabel{background-color:yellow;}')
if __name__ == '__main__':
app = QApplication(sys.argv)
main_ = main()
main_.show()
app.exec_()
But what's happening is the color of label l never changes to Red the execution directly jumps to the loop and i only see yellow colored l