External Exam Download Resources Web Applications Games Recycle Bin

Roll a dice with a list of images (better way)

dice2.py

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

dice_images = ["dice1.bmp","dice2.bmp","dice3.bmp",
               "dice4.bmp","dice5.bmp","dice6.bmp"]
import random
dice = pygame.image.load(random.choice(dice_images))

while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True

  screen.blit(dice, (150, 100))
  
  pygame.display.flip()
pygame.quit()
                    

put image files + python file into same folder: