類似的問題:Pygame screen freezes when I close it
沒有任何輸入在我的課本 和所有谷歌似乎收率 使用pygame 本身導致此問題。
這些結果可能解決了您遇到的同樣問題。這是從livewires的games.py文件的相關部分,無處它調用pygame.quit()
:
def handle_events (self):
"""
If you override this method in a subclass of the Screen
class, you can specify how to handle different kinds of
events. However you must handle the quit condition!
"""
events = pygame.event.get()
for event in events:
if event.type == QUIT:
self.quit()
elif event.type == KEYDOWN:
self.keypress (event.key)
elif event.type == MOUSEBUTTONUP:
self.mouse_up (event.pos, event.button-1)
elif event.type == MOUSEBUTTONDOWN:
self.mouse_down (event.pos, event.button-1)
def quit (self):
"""
Calling this method will stop the main loop from running and
make the graphics window disappear.
"""
self._exit = 1
def mainloop (self, fps = 50):
"""
Run the pygame main loop. This will animate the objects on the
screen and call their tick methods every tick.
fps -- target frame rate
"""
self._exit = 0
while not self._exit:
self._wait_frame (fps)
for object in self._objects:
if not object._static:
object._erase()
object._dirty = 1
# Take a copy of the _objects list as it may get changed in place.
for object in self._objects [:]:
if object._tickable: object._tick()
self.tick()
if Screen.got_statics:
for object in self._objects:
if not object._static:
for o in object.overlapping_objects():
if o._static and not o._dirty:
o._erase()
o._dirty = 1
for object in self._objects:
if object._dirty:
object._draw()
object._dirty = 0
self._update_display()
self.handle_events()
# Throw away any pending events.
pygame.event.get()
的退出事件只是設置它會把你出的mainloop
功能while循環的一個標誌。我猜如果你在你的Python目錄中找到這個文件,並在mainloop
的最後一行後面加上一個pygame.quit()
,它會解決你的問題。
你說的崩潰是什麼意思?它是否會拋出異常或錯誤?此外,pygame使用SDL而不是Tkinter,SDL已知需要一段時間才能關閉。 –
通過崩潰我的意思是程序變得沒有響應,我不得不去任務管理器退出它。 另外,事實證明我不應該從IDLE運行pygame,我應該直接從Python運行它。我不知道爲什麼,但我仍然想知道。從IDLE運行它確保pygame程序無響應。 – Louis93
嗯,這很奇怪。當你在IDLE之外運行時會發生什麼? –