I have two multiple threads, and my aim is to print "mouse1" and "mouse2" seperately using the two multiple threads. But the program isn't working. It prints nothing, and it can't be closed properly.
import threading
import pygame
screen = pygame.display.set_mode((800, 800))
def mouse1():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
print('mouse1')
else:
pass
def mouse2():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
print('mouse2')
else:
pass
t2 = threading.Thread(target=mouse1)
t1 = threading.Thread(target=mouse2)
t1.start()
t2.start()
t1.join()
t2.join()
I expect when the mouse button is clicked, the output to be many "mouse1" and "mouse2".