Advertisement
Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. from PyQt5.QtWidgets import (QWidget, QApplication, QPushButton,
  2.         QLabel, QHBoxLayout, QSizePolicy)
  3. from PyQt5.QtGui import QColor
  4. from PyQt5.QtCore import QPropertyAnimation, pyqtProperty
  5. import sys
  6.  
  7. class MyLabel(QLabel):
  8.    
  9.     def __init__(self, text):
  10.         super().__init__(text)
  11.  
  12.     def _set_color(self, col):
  13.        
  14.         palette = self.palette()
  15.         palette.setColor(self.foregroundRole(), col)
  16.         self.setPalette(palette)
  17.  
  18.     color = pyqtProperty(QColor, fset=_set_color)
  19.  
  20.  
  21. class Example(QWidget):
  22.  
  23.     def __init__(self):
  24.         super().__init__()
  25.  
  26.  
  27.         self.initUI()
  28.        
  29.        
  30.     def initUI(self):    
  31.  
  32.         hbox = QHBoxLayout(self)
  33.        
  34.         self.button = QPushButton("Start", self)
  35.         self.button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
  36.         hbox.addWidget(self.button)
  37.        
  38.         hbox.addSpacing(40)
  39.  
  40.         self.label = MyLabel("Summer")
  41.         font = self.label.font()
  42.         font.setPointSize(35)
  43.         self.label.setFont(font)
  44.         hbox.addWidget(self.label)
  45.  
  46.         self.anim = QPropertyAnimation(self.label, b"color")
  47.         self.anim.setDuration(2500)
  48.         self.anim.setLoopCount(2)
  49.         self.anim.setStartValue(QColor(0, 0, 0))
  50.         self.anim.setEndValue(QColor(255, 255, 255))
  51.  
  52.         self.button.clicked.connect(self.anim.start)
  53.        
  54.         self.setGeometry(300, 300, 380, 250)
  55.         self.setWindowTitle('Color anim')
  56.         self.show()    
  57.        
  58. if __name__ == "__main__":
  59.    
  60.     app = QApplication([])
  61.     ex = Example()
  62.     ex.show()
  63.     app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement