python stürzt ab: scriptfehler?

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Py19917062
User
Beiträge: 113
Registriert: Freitag 30. Januar 2009, 00:53
Wohnort: Dortmund
Kontaktdaten:

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?
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.
Py19917062
User
Beiträge: 113
Registriert: Freitag 30. Januar 2009, 00:53
Wohnort: Dortmund
Kontaktdaten:

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?
Benutzeravatar
str1442
User
Beiträge: 520
Registriert: Samstag 31. Mai 2008, 21:13

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.
Py19917062
User
Beiträge: 113
Registriert: Freitag 30. Januar 2009, 00:53
Wohnort: Dortmund
Kontaktdaten:

ok danke
Antworten