将pygame.event输出设置为Variable

时间:2015-09-05 23:55:42

标签: python-3.x pygame

我正在尝试确定如何从pygame事件中获取输出并将输出存储到我稍后可以调用的变量中。

import pygame
pygame.init()
display_width = 640
display_height = 480


gameDisplay = pygame.display.set_mode((display_width,display_height),pygame.RESIZABLE)


if (__name__ == "__main__"):

run = True

while (run):
    for event in pygame.event.get():
        if event.type == pygame.VIDEORESIZE
            print(event)

文档说pygame.VIDEORESIZE输出(大小,w,h)从控制台输出显而易见:

<Event(16-VideoResize {'w': 640, 'h': 480, 'size': (640, 480)})>

所以,我试图将整个输出存储为变量:

import pygame
pygame.init()
display_width = 640
display_height = 480

gameDisplay = pygame.display.set_mode((display_width,display_height),pygame.RESIZABLE)

if (__name__ == "__main__"):

run = True

while (run):
    for event in pygame.event.get():
        if event.type == pygame.VIDEORESIZE:
            output = pygame.VIDEORESIZE
            print(output)

但是,无论我调整窗口的大小,控制台都会将输出返回为16。

1 个答案:

答案 0 :(得分:1)

您正在将output设置为videoresize事件类型。你应该改为output = event