Closing Pygame Window

前端 未结 8 709
不知归路
不知归路 2020-12-31 03:24

I just spent a fair amount of time finding a 64-bit installation of pygame to use with python 3.3, (here) and now am trying to make a window. However, although the window op

相关标签:
8条回答
  • 2020-12-31 04:04

    if you want to make pygame close when window button x is pressed, put the code like this:

    from sys import exit
    while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    exit()
    

    We put exit() after pygame.quit(), because pygame.quit() makes the system exit and exit() closes that window.

    0 讨论(0)
  • 2020-12-31 04:08

    Not sure but try this Because you code runs fine on my system after I add pygame.quit() at the end

    import pygame
    import time
    (width, height) = (300, 200)
    screen = pygame.display.set_mode((width, height))
    pygame.display.flip()
    pygame.display.set_caption("Hello World")
    running = True
    try:
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
        pygame.quit()
    except SystemExit:
        pygame.quit()
    

    Its perhaps because as Idle is made on Tkinter and thus Tkinter and Pygame main loop do not have a mutual understanding.
    Your code will run very well on command prompt though.

    0 讨论(0)
提交回复
热议问题