Re: Chapt. 16, "Drawing art": 'dict_keys' object does not support indexing!?
I found a better solution for listing 16.7 with python3 (though it is still more lengthy than with python2):
...
import pygame, sys, random
from pygame.color import THECOLORS
keys = list(THECOLORS)
...
for i in range (100):
width = random.randint(0, 250)
height = random.randint(0, 100)
top = random.randint(0, 400)
left = random.randint(0, 500)
line_width = random.randint(1, 5)
color_name = random.choice(keys)
color = THECOLORS[color_name]
pygame.draw.rect(screen, color, [left, top, width, height], line_width)
pygame.display.flip()
....
Anybody find something more simple?
Thank you,
sandefan
|