import pygame,sys,threading,pygame.locals,pygame.font

pygame.init()

def New_window(window_x,window_y,window_name,background):
    screen = pygame.display.set_mode((window_x,window_y),0,32)
    pygame.display.set_caption(window_name)
    background_imarges = pygame.image.load(f'./imarges/background/{background}.png').convert()
    return screen,background_imarges

def New_file(screen,file_imarge,file_x,file_y,file_text,text_x,text_y,text_color,text_S,text_font):
    file_imarge = pygame.image.load(f'./imarges/{file_imarge}.png').convert()
    font = pygame.font.Font(text_font,text_S)
    file_text = font.render(file_text,True,text_color)
    screen.blit(file_imarge,(file_x,file_y))
    screen.blit(file_text,(text_x,text_y))
    return None
def Opensys(a):
    with open(a) as files:
        file = files.readlines()
        title = file[0].rstrip()
        title_x,title_y = int(file[1].rstrip()),int(file[2].rstrip())
        title_S,title_color = int(file[3].rstrip()),(int(file[4].rstrip()),int(file[5].rstrip()),int(file[6].rstrip()))
        return title,title_x,title_y,title_S,title_color
    
def first_window():
    first_window,first_window_background = New_window(400,600,'说我(TAM) ——定义你自己','first_window')
    title,title_x,title_y,title_S,title_color = Opensys('./sys/first_window/title.txt')
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.VIDEORESIZE:
                size = (event.size[0], event.size[1])
        first_window.blit(first_window_background,(0,0))
        New_file(first_window,"title_box/first_window",0,0,title,title_x,title_y,title_color,title_S,'./sys/first_window/title.ttf')

        pygame.display.flip()

    return None

t_First = threading.Thread(target = first_window)
t_First.start()
t_First.join()
pygame.quit()
