0

enter image description here

I have a problem with pep 8 and my Python code concerning Pygame constant on the next piece of code, which is sending me error E0602 "Undefined variable" when i use the pygame constant "KEYDOWN" "K_F1" K_ESCAPE"

is there any trick to solve this problem with pep8

I am a beginner and I admit that I do not find a solution to solve this problem :(

def run(self):
     """ start loop """
    loop = True
    while loop is True:
        self.windowSurface.blit(self.Sprite.home, (0, 0))
        self.pygame.display.flip()
            for event in pygame.event.get():
                if event.type == KEYDOWN:
                    if event.key == K_F1:
                        loop = False
                    elif event.key == K_ESCAPE:
                        sys.exit(1)
Sashi
  • 2,659
  • 5
  • 26
  • 38
donkan
  • 1
  • 2

1 Answers1

1

Adding pygame. in front of those constants should fix the PEP8 issue.

In your case, pygame.KEYDOWN, pygame.K_F1, and pygame.K_ESCAPE.

  • thanks a lot for your help, i made the change and pylint now sends me the error E1101 "pygame module has no 'KEYDOWN' member, :( I'm cursed – donkan Jan 09 '19 at 16:07
  • That's interesting! The documentation mentions `pygame.KEYDOWN` (https://www.pygame.org/docs/ref/key.html). Have you tried what this post suggests? https://stackoverflow.com/questions/53909155/cant-import-any-pygame-functions-e1101 – Lord Macpolius Jan 09 '19 at 16:11
  • This SO explains the E1101 issue well: https://stackoverflow.com/questions/53012461/imports-failing-in-vscode-for-pylint-when-importing-pygame/53025854#53025854 – Lord Macpolius Jan 09 '19 at 16:27
  • I just tried this method again (I had tried it yesterday without success) and I still have this damn error E1101 "Module 'pygame' has no 'KEYDOWN' member" thx for the link – donkan Jan 09 '19 at 16:33
  • You are wonderfull, thank you very much, i had to add in the header of mi script from pygame.constants import ( (all constants used in mi code) MOUSEBUTTONDOWN, QUIT, MOUSEMOTION, KEYDOWN, ect... ) – donkan Jan 09 '19 at 16:43