Answer the question
In order to leave comments, you need to log in
Why don't pygame events work on Windows in a new thread?
Pygame is running on a new thread. And for some reason it event = pygame.event.poll()
shows up all the time <Event(0-NoEvent {})>
.
However, pygame.event.get()
it only emits mouse drag events. And the strangest thing is that everything works fine on Linux, I decided to test it on Windows - and then bam .. Please help me, why is that?
Code is here . Run the breakout.py file, then click on the "Bot" button (it is the bot that opens in a new thread). And on the "Play" button, everything works as it should, because I do not create a new process.
PS The inputbox.py file is responsible for the input window. In it, in the get_key function, the loop becomes infinite, because it does not find a single event:
def get_key(game=None):
while 1:
event = pygame.event.poll()
if event.type == KEYDOWN:
return event.key
elif event.type == pygame.QUIT:
game.game_over = True
pygame.quit()
sys.exit()
else:
pass
pygame.mixer.pre_init(44100, 16, 2, 4096)
pygame.init()
pygame.font.init()
pygame.display.set_mode((width, height))
Answer the question
In order to leave comments, you need to log in
Judging by the documentation, events must be called from the main thread and processed there, otherwise, depending on the environment, it may or may not work. What are you observing. Also, if for some reason it is impossible to work with events from the main thread, the fastevent package is recommended . Original from documentation:
PS Compiled .pyc files got into your turnip. They should be removed from the repository and added to .gitignore along with the __pycache__ directories
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question