首页 > 代码库 > python2.7之pygame

python2.7之pygame

1 pygame窗口设置

pygame在导入后,第一步需要进行初始化:

  import pygame

  pygame.init()

pygame可以设置标题

  pygame.display.set_caption(gold615)

   也可以设置界面的大小

  screen=pygame.display.set_mode([640,480])#可以看到参数是一个列表

当然颜色就更别提了

  screen.fill([255,255,255])#用白色填充窗口,可以根据需求随便设置颜色.

2 事件

目前看到的python代码似乎没有事件监听部分,还是需要在循环中进行处理.

退出事件

  while True: for event in pygame.event.get(): if event.type==pygame.QUIT: sys.exit()

3 画圆pygame.draw.circle()

pygame.draw.circle(screen,[255,0,0],[100,100],30,0) #第一个参数指定画在哪里,第二个指定使用的颜色,第三个指定画的位置,第四个指定半径,第五个指定线宽.

 

python2.7之pygame