当前位置:网站首页>Exit of pyGame, idle and pycharm

Exit of pyGame, idle and pycharm

2022-07-05 07:28:00 work-harder

background :

         win8.1, python3.9.7, idle(3.9.7), pycharm(2021.3.1)

Purpose :

        pygame After operation , Click on “x" after , The interface closes when exiting , There is no need for the system to automatically prompt whether to close the program

The phenomenon :

1. The method given in a lecture is as follows ( The editor is pycharm), You can really see the program exit smoothly :

                

if event.type == pygame.QUIT:

    print("Game Over") #  Test statement 

    exit()

2. I use it python Self contained idle, Results run pygame After the app , The running window appears normally ( Code name A). Click on "x" after , There is no exit window (A), There's no hint . But according to the added test statements (print sentence ), Yes, I did . It turned out , There is a warning pop-up that requires the user to confirm whether to exit “ hide ” Behind the running window .

3. Change the above exit code to the following ,idle and pycharm Can exit normally , No additional confirmation is required .

if event.type == pygame.QUIT: # The front has  import pygame

    print("Game Over") #  Test statement 

    pygame.quit() # Don't add this line ,idle Middle window cannot exit 
    sys.exit() #  The front has import sys;  direct exit(),  Can't quit .

原网站

版权声明
本文为[work-harder]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140555475456.html