我正在pygame中制作一个小程序,但即使程序仍在运行并调用pygame.draw函数,它仍会冻结并说“不响应”。
if timer==0:
mouseMoved=False
import ctypes
ctypes.windll.user32.SetProcessDPIAware()
true_res = (ctypes.windll.user32.GetSystemMetrics(0), ctypes.windll.user32.GetSystemMetrics(1))
disp = pygame.display.set_mode(true_res,pygame.FULLSCREEN)
del ctypes
color=(0,0,0)
pos=[50,60]
pygame.Surface.fill(disp, (255,255,255))
#mouse.move(mPos[0], mPos[1])
firstMove=True
x, y = pygame.display.get_surface().get_size()
while not mouseMoved:
#mouse.move(mPos[0], mPos[1])
mouseMoved=False
pMouse=mPos
#print(pMouse)
mPos=mouse.get_position()
#print(pos)
if pos[0]+4>=x:
horiz=-1
color=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
elif pos[0]-4<=0:
horiz=1
color=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
if pos[1]-4<=0:
vert=1
color=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
elif pos[1]+4>=y:
vert=-1
color=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
pos[0]+=horiz
pos[1]+=vert
#pygame.Surface.fill(disp, (250,250,250))
pygame.draw.circle(disp, color, (pos[0], pos[1]), 9)
pygame.display.update()
#time.sleep(0.01)
if not pMouse==mPos:
if firstMove:
firstMove=False
else:
timer = 360
mouseMoved=True
#pygame.display.iconify()
#disp = pygame.display.set_mode((200,200))
pygame.display.quit()
#pygame.display.update()
print(f"moved from {mPos} to {pMouse}")
这东西应该一直运行到鼠标移开显示屏为止。
答案 0 :(得分:0)
在主while循环中,添加类似这样的内容,该内容应允许调整屏幕大小和移动屏幕。这将取决于您如何设置原始屏幕,而我们的代码示例中看不到或无法运行原始屏幕。
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
quit()
elif event.type == pg.VIDEORESIZE:
self.height = event.h
self.width = event.w
self.screen = pg.display.set_mode((self.width, self.height), pg.RESIZABLE)