问题:
如果我的鼠标光标在窗口之外,我的游戏就会运行,但是如果我将光标放在控制台内,则会出现此错误
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
这是我的代码
import pygame as pg
from Config import *
from bin import *
# initialising pygame
pg.init()
class Game():
def background(self,background):
window.blit(background, (0,0))
# defining classes for use
g = Game()
# game loop
while isrunning:
# making sure the game is running on a constant clock
time.tick(fps)
# add background
g.background(gameback)
# setting up events
for event in pg.event.get():
# closing window event
if event.type == pg.QUIT():
isrunning = False
# input events
# show finished frame
pg.display.flip()
# Last code before closing the window
# closing the window
pg.quit()
大多数变量在不同文件中定义 config file gamevars file
该程序在macOS上运行良好,我仅在Windows 10上收到此错误。 这是错误的video
答案 0 :(得分:3)
QUIT
不是方法或函数,它是一个枚举数常量,它指定事件的类型(请参见pygame.event.Event()
)。
去掉括号即可解决问题:
if event.type == pg.QUIT():
if event.type == pg.QUIT:
答案 1 :(得分:2)
pg.QUIT是一个枚举值。它基本上是一个整数。您的代码出于某种原因添加了括号;这是无效的语法。仅使用
if event.type == pg.QUIT:
您编码的内容大概是
if event.type == 4():