Differencebetween .Quit and .Quit in Pygame

What is the difference between .quit and .QUIT in pygame

QUIT is the enumerator constant for an event type (see event module). The quit event occurs when the pygame window is closed:

for event in pygame.event.get():
if event.type == pygame.QUIT:
# [...]

quit() is a function which uninitialize all pygame modules. This function should be called at the end of the applicaiition:

# initialize all imported pygame modules
pygame.init()

# application loop
while True:
# [...]

# uninitialize all pygame modules
pygame.quit()

Difference between .quit and .destroy on tkinter

.quit() causes mainloop to exit, but doesn't directly cause any widgets to be destroyed. However, if there's no code after calling mainloop then the script exits, and all widgets will be destroyed.

.destroy() will destroy a widget. If you destroy the root window then all other widgets will be destroyed and mainloop will stop.

is there a force quit option for pygame programs?

Here you compare the event type to the predefined quit function of python. This is obviously never evaluted to True.

Do instead if event.type == pygame.QUIT:.

What is the difference between root.destroy() and root.quit()?

quit() stops the TCL interpreter. This is in most cases what you want, because your Tkinter-app will also stop. It can be a problem, if you e.g. call your app from idle. idle is itself a Tkinker-app, so if you call quit() in your app and the TCL interpreter gets terminated, idle will also terminate (or get confused ).

destroy() just terminates the mainloop and deletes all widgets. So it seems to be safer if you call your app from another Tkinter app, or if you have multiple mainloops."

taken from http://www.daniweb.com/forums/thread66698.html

Python exit commands - why so many and when should each be used?

The functions* quit(), exit(), and sys.exit() function in the same way: they raise the SystemExit exception. So there is no real difference, except that sys.exit() is always available but exit() and quit() are only available if the site module is imported (docs).

The os._exit() function is special, it exits immediately without calling any cleanup functions (it doesn't flush buffers, for example). This is designed for highly specialized use cases... basically, only in the child after an os.fork() call.

Conclusion

  • Use exit() or quit() in the REPL.

  • Use sys.exit() in scripts, or raise SystemExit() if you prefer.

  • Use os._exit() for child processes to exit after a call to os.fork().

All of these can be called without arguments, or you can specify the exit status, e.g., exit(1) or raise SystemExit(1) to exit with status 1. Note that portable programs are limited to exit status codes in the range 0-255, if you raise SystemExit(256) on many systems this will get truncated and your process will actually exit with status 0.

Footnotes

* Actually, quit() and exit() are callable instance objects, but I think it's okay to call them functions.

pygame error: video system has not initialized

Your culprit is this line:

if event.type == pygame.quit():

Instead of checking for the QUIT event, you're calling the pygame.quit() function the first time your program enters the game loop, and the function uninitializes your pygame state, which then causes your game to crash the next time you try to access any pygame state.

What you want is to check if you got the pygame.QUIT event.

import pygame

pygame.init()

screen = pygame.display.set_mode((800,600))
running = True
while running:
for event in pygame.event.get():
# this should be the event pygame.QUIT
# and not the function pygame.quit()
if event.type == pygame.QUIT:
running = False


Related Topics



Leave a reply



Submit