Seite 1 von 1

python stürzt ab: scriptfehler?

Verfasst: Samstag 31. Januar 2009, 02:22
von Py19917062
nabend ^^
hab mal wieder ein problem

Code: Alles auswählen

import pygame

breite = 640
hoehe = 480
mal = pygame.draw.line

screen = pygame.display.set_mode((breite, hoehe))
running = 1

while running:
    event = pygame.event.poll()
    if event.type == pygame.QUIT:
        running = 0


    screen.fill((0, 0, 0))
    mal(screen, (255,0,0), (0,hoehe), (0,0))
        
    pygame.display.flip()
python bleib total hängen...kann auf die fenster nicht zugreifen und wenn ich wissen will was die python shell mir sagen möchte, dann taucht ein rintime error auf und ich soll mich ans support wenden

liegts am code oder liegt es am rechner?

Verfasst: Samstag 31. Januar 2009, 06:07
von BlackJack
Es fehlt ein Aufruf von `pygame.init()`.

Und statt `pygame.event.poll()` würde ich hier `pygame.event.wait()` verwenden, damit nicht so viel Rechenzeit verbraten wird.

Dann noch eine Stilfrage: Wenn man einen Wahrheitswert ausdrücken möchte, sollte man `True` und `False` statt 1 und 0 nehmen.

Verfasst: Sonntag 1. Februar 2009, 01:59
von Py19917062
darf ich erfahren wo ich pygame.init() plazieren muss und was es bewirkt?


wie wärs statt pygame.event.wait() mit

Code: Alles auswählen

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            False
oder ist pygame.event.wait() die eleganteste lösung?

Verfasst: Sonntag 1. Februar 2009, 09:42
von str1442
pygame.init() -> passed, failed
autoinitialize all imported pygame modules

Initialize all imported pygame modules. Including pygame modules
that are not part of the base modules (like font and image).

It does not raise exceptions, but instead silently counts which
modules have failed to init. The return argument contains a count
of the number of modules initialized, and the number of modules
that failed to initialize.

You can always initialize the modules you want by hand. The
modules that need it have an init() and quit() routine built in,
which you can call directly. They also have a get_init() routine
which you can use to doublecheck the initialization. Note that
the manual init() routines will raise an exception on error. Be
aware that most platforms require the display module to be
initialized before others. This init() will handle that for you,
but if you initialize by hand, be aware of this constraint.

As with the manual init() routines. It is safe to call this
init() as often as you like. If you have imported pygame modules
since the.
Also am besten am Anfang.

Ich würde auch die event.get() Schleife benutzen. Dann bekommst du auch alle Events. Zumindest habe ich es bisher immer so gemacht.

Verfasst: Sonntag 1. Februar 2009, 23:56
von Py19917062
ok danke