button_paint.py 754 B

1234567891011121314151617181920212223242526272829303132
  1. import pygame
  2. import sys
  3. import GUI
  4. from random import randint
  5. pygame.init()
  6. screen = pygame.display.set_mode((300, 300))
  7. widgets = []
  8. for j in range(30):
  9. for i in range(30):
  10. widgets.append(GUI.Button(screen, text = '', width = 10, height = 10, x = 10*j, y = 10*i))
  11. widgets.append(GUI.Button(screen, text = '', width = 10, height = 10, x = 999, y = 999))
  12. while True:
  13. for value in range(len(widgets)):
  14. widgets[value].update()
  15. for event in pygame.event.get():
  16. if event.type == pygame.QUIT:
  17. sys.exit()
  18. elif event.type == pygame.MOUSEBUTTONDOWN:
  19. for value in range(900):
  20. if widgets[value].active(key = event.button):
  21. widgets[value].set_bg_color((randint(0, 255), randint(0, 255), randint(0, 255)))
  22. pygame.display.update()