1

pygameやその他のPythonモジュール全般の補助輪であるlivewiresラッパーを介して実行しています。しかし、実行するたびに実行され、終了しようとすると応答せず、クラッシュします。

これを修正する方法についての入力は素晴らしいでしょう。私の教科書には何も入力されておらず、すべてのグーグルはpygame自体を使用したこの問題の結果であるようです。

どうやらpygameとTkinterは競合しているようですか?

前もって感謝します!

補遺-これは私が実行しようとしていたコードです:

from livewires import games

screen_w = 640
screen_h = 480

my_screen = games.Screen (wid, heit)
my_screen.mainloop()
4

2 に答える 2

4

同様の質問:Pygame画面を閉じるとフリーズします

私の教科書には何も入力されておらず、すべてのグーグルは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()

mainloopQUITイベントは、関数のwhileループから抜け出すフラグを設定するだけです。Pythonディレクトリでこのファイルを見つけてpygame.quit()、の最後の行の後にmainloop続けると、問題が解決すると思います。

于 2011-06-22T20:46:04.620 に答える
0

同意します。プログラム全体(定義などではなく、実行される部分)をwhileループに入れる必要があります。問題は、IDLEで終了したときにpygameが閉じるように指示されないことですが、IDLEの外部ではプログラムのクローズがオーバーライドされます。 pygameを閉じる必要があります。

これがループです:

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()
于 2013-04-07T02:49:50.110 に答える