1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| from PyQt5.QtWidgets import QMainWindow,QWidget,QPushButton,QLabel,QVBoxLayout,QHBoxLayout,QApplication
import sys
class Fenetre_Principale(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
fenetre_widget = QWidget()
#Boutons
self.bouton_play = QPushButton("Play")
self.bouton_play.setFixedWidth(70)
#Labels
self.label_1 = A(self)
#Layout
layoutverticalglobal=QVBoxLayout()
layoutverticalglobal.addWidget(self.bouton_play)
layoutverticalglobal.addWidget(self.label_1)
#Intégration
fenetre_widget.setLayout(layoutverticalglobal)
self.setCentralWidget(fenetre_widget)
#Fonctions Connect
self.bouton_play.clicked.connect(self.label_1.play)
class A(QLabel):
def __init__(self,ui):
QLabel.__init__(self)
self.ui=ui
self.ui.setStyleSheet("QLabel {background: pink}")
def play(self, ui):
self.ui.setStyleSheet("QLabel {background: black}")
def main(args):
appli=QApplication(args)
fenetre=Fenetre_Principale()
fenetre.show()
r=appli.exec_()
return r
if __name__=="__main__":
main(sys.argv) |