首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >移动鼠标在游戏窗口中停止游戏(游戏)

移动鼠标在游戏窗口中停止游戏(游戏)
EN

Stack Overflow用户
提问于 2019-12-20 17:44:07
回答 1查看 47关注 0票数 2

问题:

如果我的鼠标光标在窗口外,我的游戏运行,但如果我的光标在控制台内给我这个错误。

代码语言:javascript
复制
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

这是我的代码

代码语言:javascript
复制
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()

大多数变量都是在不同的文件配置文件 游戏文件中定义的。

这个程序在macOS上运行得很好--我只在windows 10上得到这个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-20 17:49:22

pg.QUIT是一个枚举值。基本上是个整数。您的代码由于某种原因添加了括号;这是无效的语法。仅用

代码语言:javascript
复制
if event.type == pg.QUIT:

你编码的东西有点像

代码语言:javascript
复制
if event.type == 4():
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59429390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档