我用 python 3.3 和 PySDL2 0.5 运行 win7。创建表面时(无论采用何种方法),我都会得到一个 LP_SDL_Surface 而不是 SDL_Surface。LP_SDL_Surface 缺少您期望它具有的任何方法和属性。这是使用文档中的示例代码的问题:
import os
os.environ["PYSDL2_DLL_PATH"] = os.path.dirname(os.path.abspath(__file__))
import sys
import ctypes
from sdl2 import *
def main():
SDL_Init(SDL_INIT_VIDEO)
window = SDL_CreateWindow(b"Hello World",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
592, 460, SDL_WINDOW_SHOWN)
windowsurface = SDL_GetWindowSurface(window)
image = SDL_LoadBMP(b"exampleimage.bmp")
SDL_BlitSurface(image, None, windowsurface, None)
print(image.h)
SDL_UpdateWindowSurface(window)
SDL_FreeSurface(image)
running = True
event = SDL_Event()
while running:
while SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == SDL_QUIT:
running = False
break
SDL_DestroyWindow(window)
SDL_Quit()
return 0
if __name__ == "__main__":
sys.exit(main())
回溯是:
Traceback (most recent call last):
File "C:/.../test.py", line 35, in <module>
sys.exit(main())
File "C:/.../test.py", line 17, in main
print(image.h)
AttributeError: 'LP_SDL_Surface' object has no attribute 'h'
谷歌搜索“LP_SDL_Surface”会带来 0 (!) 个结果。