Reputation: 73
import pygame
import color
def renderText(msg, topleft, font_type, font_size, color):
font = pygame.font.SysFont(font_type, font_size)
text = font.render(msg, True, color)
screen.blit(text, topleft)
def updateScreen(scr, clock):
global screen
screen = scr
screenType = "main" # default main screen
size = 25
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
if screenType == "main":
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
size+=1
mainScreen(size)
pygame.display.update()
clock.tick(30)
def mainScreen(size):
screen.fill(color.GREEN) # color.GREEN = (0, 255, 0)
renderText("Single mode", (120, 120), 'comicsansms', size, color.RED) # color.RED = (255, 0, 0)
if __name__ == "__main__":
pygame.init()
screen = pygame.display.set_mode((676, 459))
pygame.display.set_caption('MATGO')
clock = pygame.time.Clock()
main = threading.Thread(target = updateScreen, args = (screen, clock))
main.start()
I searched for this problem and generally answer says that pygame.event.get() should be called for interacting with OS. However, it just stops and suddenly not responding pops up even though pygame.event.get() is called in the loop. Close button doesn't work either.
(I used threading because I want to seperate GUI handler from main file)
Upvotes: 1
Views: 308
Reputation: 1604
There are multiple places where you can find advice that event handling should be called from the main thread.
Even official documentation says:
The event subsystem should be called from the main thread. If you want to post events into the queue from other threads, please use the fastevent package.
Do not mix this with ability to send events from separate thread.
Upvotes: 1