Task one: to switch between the simple color screen
import pygame from pygame.locals import * pygame.init() win = pygame.display.set_mode((800,600),DOUBLEBUF|HWSURFACE) for i in range(10): win.fill((0,255,0)) if i%2==0: win.fill((255,0,0)) pygame.time.wait(500) pygame.display.flip()
Note specific point:
Pygame.locals need to import in order to use later doublebuf and hwsurface
But how to define the color depth of the screen that is set up not really understand.
Task Two: Capture events mouse movements, and a circle at the location of the mouse painting
import pygame from pygame.locals import * import sys pygame.init() win = pygame.display.set_mode((800,600),DOUBLEBUF|HWSURFACE) while True: ev = pygame.event.get() for i in ev: if not i ==None: print(i) if i.type==QUIT: pygame.quit() elif i.type==MOUSEMOTION: pygame.draw.circle(win,(255,0,0),i.pos,3, 3) pygame.display.flip()
The question: pygame.draw.circle function can not add keywords such as radius =, or width =, can write directly to the value, I do not know why.
There are in the process of capturing events must join an infinite loop, otherwise the event would instantly print out, and then later before the incident, the capture has ended.