我正在学习Python的PYGAME模块,这样我就可以制作游戏了,而且我对它还相当陌生.我正在看一篇教程,在下面的代码中,当for循环判断pygame.QUIT事件时,run变量变成了False,而pygame.Quit()退出了pyGame.

我的问题是,why is the pygame.QUIT being checked when the 'X' button will close the window?

Youtube tutorial code

推荐答案

When the X button is pressed, an event object is created and added to the event queue. The event objects are retrieved with pygame.event.get(). The type property indicates the type of the event.
If you do not check event.type == pygame.QUIT and do not set run = False, the loop will never end (endless loop), the application will never terminate and the window will not close.
pygame.quit() deinitializes all pygame modules, which also deinitializes the display module and causes the window to close. The window is also closed when the application exits after your script is finished.

Python相关问答推荐

在Transformer中使用LabelEncoding的ML模型管道

仅对matplotlib的条标签中的一个条标签应用不同的格式

Matplotlib轮廓线值似乎不对劲

使用Ubuntu、Python和Weasyprint的Docker文件-venv的问题

DuckDB将蜂巢分区插入拼花文件

理解Python的二分库:澄清bisect_left的使用

Polars比较了两个预设-有没有方法在第一次不匹配时立即失败

如何在Django基于类的视图中有效地使用UTE和RST HTIP方法?

将9个3x3矩阵按特定顺序排列成9x9矩阵

将输入聚合到统一词典中

当递归函数的返回值未绑定到变量时,非局部变量不更新:

未知依赖项pin—1阻止conda安装""

在嵌套span下的span中擦除信息

与命令行相比,相同的Python代码在Companyter Notebook中运行速度慢20倍

* 动态地 * 修饰Python中的递归函数

关于两个表达式的区别

Beautifulsoup:遍历一个列表,从a到z,并解析数据,以便将其存储在pdf中.

Python 3试图访问在线程调用中实例化的类的对象

如何根据rame中的列值分别分组值

Pandas 数据帧中的枚举,不能在枚举列上执行GROUP BY吗?