-1

I've just started my code (python 3.8.2) and VScode (version 1.43.0) came up with the "Module 'pygame.locals' has no 'QUIT'" in the line if event.type == pg.locals.QUIT:(I've imported pygame as "pg"). I've looked around and some people said to do from pygame.locals import * and just do if event.type == QUIT but when I do that I get "Undefined variable 'QUIT'" (it also states that "QUIT" is an int?). So I'm not too sure whats going on.

(Stack overflow article I looked at)

here's all of the relevant code:

import tkinter as tk
import pygame as pg
import threading as thr
from pygame.locals import *

def pygameQuitSubprocess():
    while True:
        for event in pg.event.get():
            if event.type == QUIT:
                quit()
    pass

just for context, I am planning to run this function in a subprocess so I can run the rest of my code at the same time. If anyone can tell me why that would be a bad idea or why that wouldn't work or so forth, please do, I am very new to threading. But this isn't super important right now.

  • I would just do `if event.type == pg.QUIT` and ignore the linter message; as you can see when you run your code, it's not a runtime error. Take a look here: https://stackoverflow.com/a/53025854/142637 – sloth Mar 16 '20 at 13:13
  • 1
    Also, don't use multithreading or subprocessing if you don't actually need to. And if you really need to run another thread or process, the pygame window and event handling should be done in your main thread. – sloth Mar 16 '20 at 13:19
  • @sloth thank you for your insight, ill re-think my approach, also thanks for the link, I believe it will come in very handy – Zejammydodger Mar 16 '20 at 14:56

0 Answers0