SHARE
TWEET

click_function help

a guest Nov 13th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3.  
  4. from UIComponents import *
  5.  
  6. pygame.init()
  7.  
  8. (WIDTH, HEIGHT) = (800, 600)
  9.  
  10. WHITE = (255, 255, 255)
  11. GREEN = (0, 255, 0)
  12. BLACK = (0, 0, 0)
  13. RED = (255, 0, 0)
  14.  
  15. DICE = (300, 200, 200, 200)
  16.  
  17. TITLE = pygame.display.set_caption("Testing pygame in IDLE")
  18. SCREEN = pygame.display.set_mode((WIDTH, HEIGHT))
  19.  
  20. randNum = random.randint(1, 6)
  21.  
  22. #My click function
  23. def click():
  24.     if button.color == GREEN:
  25.         button.color = RED
  26.     else:
  27.         button.color = GREEN
  28. ####################################
  29. #My button
  30. button = Button((350, 450, 100, 50), (0, 0), GREEN, 255,  "Click Me", font_size=10,  click_function=click)
  31. ######################################
  32.  
  33. def die():
  34.     if randNum == 1:
  35.         pygame.draw.circle(SCREEN, RED, (400, 300), 10)
  36.     elif randNum == 2:
  37.         pygame.draw.circle(SCREEN, RED, (365, 300), 10)
  38.         pygame.draw.circle(SCREEN, RED, (435, 300), 10)
  39.     elif randNum == 3:
  40.         pygame.draw.circle(SCREEN, RED, (330, 230), 10)
  41.         pygame.draw.circle(SCREEN, RED, (395, 290), 10)
  42.         pygame.draw.circle(SCREEN, RED, (460, 360), 10)
  43.     elif randNum == 4:
  44.         pygame.draw.circle(SCREEN, RED, (330, 260), 10)
  45.         pygame.draw.circle(SCREEN, RED, (330, 350), 10)
  46.         pygame.draw.circle(SCREEN, RED, (460, 260), 10)
  47.         pygame.draw.circle(SCREEN, RED, (460, 350), 10)
  48.     elif randNum == 5:
  49.         pygame.draw.circle(SCREEN, RED, (330, 260), 10)
  50.         pygame.draw.circle(SCREEN, RED, (330, 350), 10)
  51.         pygame.draw.circle(SCREEN, RED, (460, 260), 10)
  52.         pygame.draw.circle(SCREEN, RED, (460, 350), 10)
  53.         pygame.draw.circle(SCREEN, RED, (393, 309), 10)
  54.     elif randNum == 6:
  55.         pygame.draw.circle(SCREEN, RED, (330, 260), 10)
  56.         pygame.draw.circle(SCREEN, RED, (330, 350), 10)
  57.         pygame.draw.circle(SCREEN, RED, (460, 260), 10)
  58.         pygame.draw.circle(SCREEN, RED, (460, 350), 10)
  59.         pygame.draw.circle(SCREEN, RED, (393, 260), 10)
  60.         pygame.draw.circle(SCREEN, RED, (393, 350), 10)
  61.  
  62.    
  63.  
  64. gameExit = False
  65.  
  66. while not gameExit:
  67.     for event in pygame.event.get():
  68.         if event.type == pygame.QUIT:
  69.             gameExit = True        
  70.  
  71.     SCREEN.fill(BLACK)
  72.     pygame.draw.rect(SCREEN, WHITE, DICE)
  73.    
  74.  
  75.     die()
  76.     #Drawing my button to the screen
  77.     button.draw(SCREEN)
  78.     #################################
  79.     pygame.display.update()
  80.  
  81. pygame.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top