J
jedi200581
Hi,
I'm trying to retreive mouse event in a python thread using pygame.
It's not working and I don't know why! Here is the code:
<snippet on>
import pygame, sys, os, threading
from pygame.locals import *
from threading import *
class Display(Thread) :
"""Class managing display"""
def __init__(self, xRes = 640, yRes = 480):
Thread.__init__(self)
#initializing display
self._xRes = xRes
self._yRes = yRes
pygame.display.init()
self._window = pygame.display.set_mode((xRes, yRes))
pygame.display.set_caption('Display')
self._screen = pygame.display.get_surface()
pygame.display.flip()
self._log = []
def input(self, event):
if event.type == KEYDOWN:
sys.exit(0)
else:
print event
def run(self):
print "starting event handling thread"
i = 0
while True:
self.input(pygame.event.wait())
disp = Display()
disp.start()
<snippet off>
When I put the content of the run and input functions in the main
thread, it's working, why not in the thread?
I'm trying to retreive mouse event in a python thread using pygame.
It's not working and I don't know why! Here is the code:
<snippet on>
import pygame, sys, os, threading
from pygame.locals import *
from threading import *
class Display(Thread) :
"""Class managing display"""
def __init__(self, xRes = 640, yRes = 480):
Thread.__init__(self)
#initializing display
self._xRes = xRes
self._yRes = yRes
pygame.display.init()
self._window = pygame.display.set_mode((xRes, yRes))
pygame.display.set_caption('Display')
self._screen = pygame.display.get_surface()
pygame.display.flip()
self._log = []
def input(self, event):
if event.type == KEYDOWN:
sys.exit(0)
else:
print event
def run(self):
print "starting event handling thread"
i = 0
while True:
self.input(pygame.event.wait())
disp = Display()
disp.start()
<snippet off>
When I put the content of the run and input functions in the main
thread, it's working, why not in the thread?