pygame.event.Event()。type == pygame.QUIT,confusion [英] pygame.event.Event().type == pygame.QUIT, confusion

查看:1528
本文介绍了pygame.event.Event()。type == pygame.QUIT,confusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑pygame循环中的这些行:

Consider these lines in the pygame loop:

ev = pygame.event.poll()
ev.type == pygame.QUIT

From: http://openbookproject.net/thinkcs/python/english3e/pygame.html

根据我的理解,函数 pygame.event.poll()在pygame包的事件模块中创建一个Event类的实例。

From what I understand the function pygame.event.poll() creates an instance of the Event class in the event module of the pygame package.

I。现在 ev.type 是一个属性调用(?),但是我怎么知道它可以有哪些值呢?你怎么能从pygame文档告诉它它有可能等于pygame.QUIT?

I. Now ev.type is an attribute call(?) but how do I know which values it can have? How can you even tell from the pygame documentation that it has the possibility to equal pygame.QUIT?

II。什么是pygame.QUIT?它如何获得值?

II. What exactly is pygame.QUIT? How does it get a value?

III。 help('pygame.QUIT') pygame.QUIT = class int(object)

推荐答案

ev = pygame.event.poll()

是对从事件队列返回单个事件的函数的调用(基本上,你的应用程序可能想知道的事情)。它将该事件(它是一个 Event 对象)分配给变量 ev

is a call to a function that returns a single event from the event queue (basically, a list of things that have happened that your application might want to know about). It assigns that event (which is an Event object) to the variable ev.

ev.type

类型的类型属性事件对象,它是一个数字常量。

gets the value of the type attribute of that Event object, which is a numerical constant.

== pygame.QUIT

检查它是否等于定义为 pygame.QUIT 的数字常数。

checks to see if it's equal the numerical constant defined as pygame.QUIT.

可能的事件类型列在 http://www.pygame.org/docs/ref/event.html - 我已复制(也列出了每个事件传递的相关属性):

The possible event types are listed at http://www.pygame.org/docs/ref/event.html - I've copy-pasted the list here as well (which also lists the associated attributes passed with each event):

QUIT             none
ACTIVEEVENT      gain, state
KEYDOWN          unicode, key, mod
KEYUP            key, mod
MOUSEMOTION      pos, rel, buttons
MOUSEBUTTONUP    pos, button
MOUSEBUTTONDOWN  pos, button
JOYAXISMOTION    joy, axis, value
JOYBALLMOTION    joy, ball, rel
JOYHATMOTION     joy, hat, value
JOYBUTTONUP      joy, button
JOYBUTTONDOWN    joy, button
VIDEORESIZE      size, w, h
VIDEOEXPOSE      none
USEREVENT        code

这篇关于pygame.event.Event()。type == pygame.QUIT,confusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆