stub.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
  2. from PyQt5.QtGui import QPixmap, QPainter, QColor, QPen
  3. from PyQt5.QtCore import Qt
  4. from random import randint, choice
  5. class MainWindow(QMainWindow):
  6. def __init__(self):
  7. super().__init__()
  8. self.initUI()
  9. def initUI(self):
  10. self.label = QLabel()
  11. canvas = QPixmap(400, 300)
  12. canvas.fill(Qt.white)
  13. self.label.setPixmap(canvas)
  14. self.setCentralWidget(self.label)
  15. self.draw_something()
  16. def draw_something(self):
  17. colors = [
  18. "#ffd141",
  19. "#376f9f",
  20. "#0d1f2d",
  21. "#e9ebef",
  22. "#eb5160",
  23. ]
  24. painter = QPainter(self.label.pixmap())
  25. pen = QPen()
  26. pen.setWidth(3)
  27. pen.setColor(QColor("red"))
  28. painter.setPen(pen)
  29. for n in range(10000):
  30. pen.setColor(QColor(choice(colors)))
  31. painter.setPen(pen)
  32. painter.drawPoint(
  33. 200 + randint(-100, 100),
  34. 150 + randint(-100, 100),
  35. )
  36. painter.end()
  37. if __name__ == '__main__':
  38. import sys
  39. app = QApplication(sys.argv)
  40. window = MainWindow()
  41. window.show()
  42. sys.exit(app.exec_())