头文件

import pygame

文档

>>> import pygame
>>> help(pygame.Surface)
Help on class Surface in module pygame:

class Surface(builtins.object)
 |  Surface((width, height), flags=0, depth=0, masks=None) -> Surface
 |  Surface((width, height), flags=0, Surface) -> Surface
 |  pygame object for representing images
 |
 |  Methods defined here:
 |
 |  __copy__(...)
 |      copy() -> Surface
 |      create a new copy of a Surface
 |
 |  __init__(self, /, *args, **kwargs)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  blit(...)
 |      blit(source, dest, area=None, special_flags = 0) -> Rect
 |      draw one image onto another
 |
 |  convert(...)
 |      convert(Surface) -> Surface
 |      convert(depth, flags=0) -> Surface
 |      convert(masks, flags=0) -> Surface
 |      convert() -> Surface
 |      change the pixel format of an image
 |
 |  convert_alpha(...)
 |      convert_alpha(Surface) -> Surface
 |      convert_alpha() -> Surface
 |      change the pixel format of an image including per pixel alphas
 |
 |  copy(...)
 |      copy() -> Surface
 |      create a new copy of a Surface
 |
 |  fill(...)
 |      fill(color, rect=None, special_flags=0) -> Rect
 |      fill Surface with a solid color
 |
 |  get_abs_offset(...)
 |      get_abs_offset() -> (x, y)
 |      find the absolute position of a child subsurface inside its top level parent
 |
 |  get_abs_parent(...)
 |      get_abs_parent() -> Surface
 |      find the top level parent of a subsurface
 |
 |  get_alpha(...)
 |      get_alpha() -> int_value or None
 |      get the current Surface transparency value
 |
 |  get_at(...)
 |      get_at((x, y)) -> Color
 |      get the color value at a single pixel
 |
 |  get_at_mapped(...)
 |      get_at_mapped((x, y)) -> Color
 |      get the mapped color value at a single pixel
 |
 |  get_bitsize(...)
 |      get_bitsize() -> int
 |      get the bit depth of the Surface pixel format
 |
 |  get_bounding_rect(...)
 |      get_bounding_rect(min_alpha = 1) -> Rect
 |      find the smallest rect containing data
 |
 |  get_buffer(...)
 |      get_buffer() -> BufferProxy
 |      acquires a buffer object for the pixels of the Surface.
 |
 |  get_bytesize(...)
 |      get_bytesize() -> int
 |      get the bytes used per Surface pixel
 |
 |  get_clip(...)
 |      get_clip() -> Rect
 |      get the current clipping area of the Surface
 |
 |  get_colorkey(...)
 |      get_colorkey() -> RGB or None
 |      Get the current transparent colorkey
 |
 |  get_flags(...)
 |      get_flags() -> int
 |      get the additional flags used for the Surface
 |
 |  get_height(...)
 |      get_height() -> height
 |      get the height of the Surface
 |
 |  get_locked(...)
 |      get_locked() -> bool
 |      test if the Surface is current locked
 |
 |  get_locks(...)
 |      get_locks() -> tuple
 |      Gets the locks for the Surface
 |
 |  get_losses(...)
 |      get_losses() -> (R, G, B, A)
 |      the significant bits used to convert between a color and a mapped integer
 |
 |  get_masks(...)
 |      get_masks() -> (R, G, B, A)
 |      the bitmasks needed to convert between a color and a mapped integer
 |
 |  get_offset(...)
 |      get_offset() -> (x, y)
 |      find the position of a child subsurface inside a parent
 |
 |  get_palette(...)
 |      get_palette() -> [RGB, RGB, RGB, ...]
 |      get the color index palette for an 8bit Surface
 |
 |  get_palette_at(...)
 |      get_palette_at(index) -> RGB
 |      get the color for a single entry in a palette
 |
 |  get_parent(...)
 |      get_parent() -> Surface
 |      find the parent of a subsurface
 |
 |  get_pitch(...)
 |      get_pitch() -> int
 |      get the number of bytes used per Surface row
 |
 |  get_rect(...)
 |      get_rect(**kwargs) -> Rect
 |      get the rectangular area of the Surface
 |
 |  get_shifts(...)
 |      get_shifts() -> (R, G, B, A)
 |      the bit shifts needed to convert between a color and a mapped integer
 |
 |  get_size(...)
 |      get_size() -> (width, height)
 |      get the dimensions of the Surface
 |
 |  get_view(...)
 |      get_view(<kind>='2') -> BufferProxy
 |      return a buffer view of the Surface's pixels.
 |
 |  get_width(...)
 |      get_width() -> width
 |      get the width of the Surface
 |
 |  lock(...)
 |      lock() -> None
 |      lock the Surface memory for pixel access
 |
 |  map_rgb(...)
 |      map_rgb(Color) -> mapped_int
 |      convert a color into a mapped color value
 |
 |  mustlock(...)
 |      mustlock() -> bool
 |      test if the Surface requires locking
 |
 |  scroll(...)
 |      scroll(dx=0, dy=0) -> None
 |      Shift the surface image in place
 |
 |  set_alpha(...)
 |      set_alpha(value, flags=0) -> None
 |      set_alpha(None) -> None
 |      set the alpha value for the full Surface image
 |
 |  set_at(...)
 |      set_at((x, y), Color) -> None
 |      set the color value for a single pixel
 |
 |  set_clip(...)
 |      set_clip(rect) -> None
 |      set_clip(None) -> None
 |      set the current clipping area of the Surface
 |
 |  set_colorkey(...)
 |      set_colorkey(Color, flags=0) -> None
 |      set_colorkey(None) -> None
 |      Set the transparent colorkey
 |
 |  set_masks(...)
 |      set_masks((r,g,b,a)) -> None
 |      set the bitmasks needed to convert between a color and a mapped integer
 |
 |  set_palette(...)
 |      set_palette([RGB, RGB, RGB, ...]) -> None
 |      set the color palette for an 8bit Surface
 |
 |  set_palette_at(...)
 |      set_palette_at(index, RGB) -> None
 |      set the color for a single index in an 8bit Surface palette
 |
 |  set_shifts(...)
 |      set_shifts((r,g,b,a)) -> None
 |      sets the bit shifts needed to convert between a color and a mapped integer
 |
 |  subsurface(...)
 |      subsurface(Rect) -> Surface
 |      create a new surface that references its parent
 |
 |  unlock(...)
 |      unlock() -> None
 |      unlock the Surface memory from pixel access
 |
 |  unmap_rgb(...)
 |      unmap_rgb(mapped_int) -> Color
 |      convert a mapped integer color value into a Color

接口

blit()

blit(source, dest, area=None, special_flags = 0) -> Rect draw one image onto another

()

显示窗口

pygame.display.flip()

处理事件

while 1:
  # 使用event.wait来等待事件
  if pygame.event.wait().type in (QUIT, ):
    break

如果有任何问题请发邮件到 isteps@126.com


广告内容, 如果不忙, 跪求点击