2011-06-22 4 views
1

私は、一般的にpygameや他のpythonモジュールのためのトレーニングホイールであるlivewiresラッパーを通して実行しています。実行するたびに実行され、終了しようとすると応答しなくなり、クラッシュします。IDLEから実行した後に終了しようとすると、pygameがフリーズします!

これを修正する方法についてのご意見は素晴らしいと思います。私の教科書には何も入力されておらず、すべてのgoogleはpygame自体を使ってこの問題の結果であると思われます。

明らかにパイゲームとTkinterは競合しているようですか?

ありがとうございます! -

補遺これは私が実行しようとしていたコードは次のとおりです。

from livewires import games 

screen_w = 640 
screen_h = 480 

my_screen = games.Screen (wid, heit) 
my_screen.mainloop() 
+1

クラッシュとはどういう意味ですか:ここ

はループがありますか?例外やエラーがスローされますか?また、pygameはTkinterではなくSDLを使用し、SDLはシャットダウンに時間がかかることが知られています。 –

+1

クラッシュすると、プログラムが応答しなくなり、終了するにはタスクマネージャーに行く必要があります。 また、私はIDLEからPygameを実行してはならないことが判明しました。私はPythonから直接実行する必要があります。確かになぜ、私はまだ知りたいと思うかわからない。 IDLEから実行すると、pygameプログラムが応答しなくなります。 – Louis93

+0

うーん、それは変です。 IDLEの外で実行するとどうなりますか? –

答えて

4

同様の質問:Pygame screen freezes when I close it

あり、任意の入力は私の教科書 ではなく、すべてのGoogleはあり得ているようです 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() 

QUITイベントだけmainloop機能でwhileループの外にあなたをドロップフラグを設定します。あなたのPythonディレクトリでこのファイルを見つけてpygame.quit()を最後の行の後にmainloopに置くと、それがあなたの問題を解決するだろうと推測しています。

0

私は同意します。問題は、PygameはIDLEで終了したときに終了するように指示されていませんが、IDLEの外側ではプログラムのオーバーライドが終了してしまうという問題があります(問題は、定義とそうでない部分を実行する部分です)。パイゲームを終了する必要があります。

done = False 
while done==False: 
    # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT 
    for event in pygame.event.get(): # User did something 
     if event.type == pygame.QUIT: # If user clicked close 
      done=True # Flag that we are done so we exit this loop 

    #Main program here 

pygame.quit()