Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在游戏窗口中移动鼠标可停止游戏(pygame)_Python_Pygame - Fatal编程技术网

Python 在游戏窗口中移动鼠标可停止游戏(pygame)

Python 在游戏窗口中移动鼠标可停止游戏(pygame),python,pygame,Python,Pygame,问题: 如果我的鼠标光标在窗口外,我的游戏将运行,但如果我的光标在控制台内,则会出现此错误 Traceback (most recent call last): File "c:/Users/jackw/Desktop/New folder/main.py", line 36, in <module> if event.type == pg.QUIT(): TypeError: 'int' object is not callable 大多数变量在不同的文件中定义 这

问题:

如果我的鼠标光标在窗口外,我的游戏将运行,但如果我的光标在控制台内,则会出现此错误

Traceback (most recent call last):
  File "c:/Users/jackw/Desktop/New folder/main.py", line 36, in <module>
    if event.type == pg.QUIT():
TypeError: 'int' object is not callable
大多数变量在不同的文件中定义

这个程序在macOS上运行得很好,我只是在Windows10上遇到这个错误。
这是一个bug的例子。QUIT是一个枚举值。它基本上是一个整数。由于某种原因,您的代码添加了括号;这是无效的语法。仅使用

if event.type == pg.QUIT:
你写的代码模糊不清

if event.type == 4():

QUIT
不是一个方法或函数,它是一个枚举数常量,用于指定事件的类型(请参阅)

拆下支架以解决问题:

如果event.type==pg.QUIT():

如果event.type==pg.QUIT: