Home>
I am in trouble because the image is displayed or not displayed, or the subsequent operation cannot be performed.
Please advise a circuit that can operate while the image is displayed.

The image below is not displayed. You can print.

import pygame
def main ():
    Initialize pygame.init () # Pygame
    screen = pygame.display.set_mode ((500, 500)) #Create screen
    img1 = pygame.image.load ("A.png")
    screen.blit (img1, (10, 10))
    while True:
        pygame.display.update () # Execute drawing process
        for e in pygame.event.get ():
            if e.type == pygame.QUIT: # end event
                pygame.quit () Close the #pygame window
                return
import random
print ("Please enter the number")
a = input ("number:")
b = int (a)
c = random.randint (1,3)
main ()

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― --------
An image is displayed here, but if you do not close the image, the operation after that will not be performed.

import pygame
def main ():
    Initialize pygame.init () # Pygame
    screen = pygame.display.set_mode ((500, 500)) #Create screen
    img1 = pygame.image.load ("A.png")
    screen.blit (img1, (10, 10))
    while True:
        pygame.display.update () # Execute drawing process
        for e in pygame.event.get ():
            if e.type == pygame.QUIT: # end event
                pygame.quit () Close the #pygame window
                return
main ()
import random
print ("Please enter the number")
a = input ("number:")
b = int (a)
c = random.randint (1,3)
  • Answer # 1

    Like multithreading

    import pygame
    def main ():
        Initialize pygame.init () # Pygame
        screen = pygame.display.set_mode ((500, 500)) #Create screen
        img1 = pygame.image.load ("A.png")
        screen.blit (img1, (10, 10))
        while True:
            pygame.display.update () # Execute drawing process
            for e in pygame.event.get ():
                if e.type == pygame.QUIT: # end event
                    pygame.quit () Close the #pygame window
                    return
    import random
    def func_1 ():
        print ("Please enter the number")
        a = input ("number:")
        b = int (a)
        c = random.randint (1,3)
    from threading import Thread
    p = Thread (target = func_1)
    p.start ()
    main ()