I was writing a paused screen for my game, the paused screen will be activated whenever the pygame window loses focus, here is my code:
import pygame
from sys import exit
pygame.init()
screen = pygame.display.set_mode((500, 500))
clock = pygame.time.Clock()
FPS = 60
while True:
screen.fill('Black')
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.ACTIVEEVENT:
if event.state == 0:
# paused screen goes here
pygame.display.update()
from the documentation I read, the event I should check for is pygame.ACTIVEEVENT and that event has 2 attributes: event.gain and event.state. However, when I tried to access one of them, it prompts an error:
pygame 2.1.2 (SDL 2.0.18, Python 3.10.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "D:\WorkDir\Dinosaur\test.py", line 20, in <module>
if event.state == 0:
AttributeError: 'Event' object has no attribute 'state'
I searched up answers online but I couldn't find any. I found a question that is somewhat related to this:
In pygame for event.type == ACTIVEEVENT, where is the documentation on what the different event.state and event.gain parameters mean?
I tried the code from the accepted answer but the bug was still there:
Traceback (most recent call last): File "D:\WorkDir\Dinosaur\test.py", line 28, in <module> main() File "D:\WorkDir\Dinosaur\test.py", line 18, in main if e.state & APPMOUSEFOCUS == APPMOUSEFOCUS: AttributeError: 'Event' object has no attribute 'state'
