多线程下按键检测用不了

大家好
最近我在和我亲爱的同学编程一个项目
可是遇到了一些“小”问题——pygame按键检测莫名的用不了了!
下面是源码(还有一些图片素材就没上传)

'''主程序(其他的都是图片素材)'''
import pygame, sys, time, threading    #引库”pygame“、”sys“、”time“、“threading”
from pygame.constants import * 

pygame.init()   #初始化pygame
list = []   #创建列表,命名为“list”
pygame.display.set_caption("桌面宠物2023春节限定")  #设置窗口标题
screen = pygame.display.set_mode((300, 300))    #设置窗口大小

# def playSound(musicFile):   #定义播放音乐
#     sound = pygame.mixer.Sound(musicFile)
#     sound.play()

myfont = pygame.font.Font(None,60)    #设置字体大小
'''加载图片'''
bg = pygame.image.load("bg.jpg")    #加载图片“bg.jpg“命名为”bg“
mouth_open = pygame.image.load("mouth_open.png")    #加载图片“mouth_open.png”并命名为”mouth_open“
mouth_close = pygame.image.load("mouth_close.png")  #加载图片“mouth_close.png”并命名为”mouth_close“
screen.blit(bg, (0, 0)) #显示背景图片“bg.jpg”
screen.blit(mouth_close, (0, 0))    #显示背景图片“mouth_close.png”
pygame.display.update()  # 更新pygame窗口

def refresh (): #创建函数:刷新窗口(为多线程用),命名为“refresh”
    while True: #开启循环
        pygame.display.update()  #更新pygame窗口
        time.sleep(1) #设置1秒刷新一次pygame窗口
        # print("刷新成功!")    告诉我:刷新成功了

def window ():   #创建函数:主程序(为多线程用),命名为“window”
    while True: #开启循环

        for event in pygame.event.get():    #开启键盘监测

            if event.type == QUIT:   #如果点击窗口的X
                pygame.quit()   #卸载pygame模块
                sys.exit()  #结束程序

            elif event.type == KEYDOWN:  #否则如果键盘按下
                if event.key == K_s: #如果按下“S”键
                    screen.blit(mouth_open, (0, 0)) #显示图片“mouth_open”
                    pygame.display.update()   #更新pygame窗口
                    time.sleep(3)   #等待3秒
                    screen.blit(mouth_close, (0, 0))    #显示图片“mouth_open”
                    pygame.display.update()   #更新pygame窗口

        pygame.display.update() #更新pygame窗口

thread1 = threading.Thread(target= refresh) #创建多线程,运行函数:“refresh”
thread2 = threading.Thread(target= window)  #创建多线程,运行函数:“window”

# thread1.start()   #启动线程1
thread2.start()   #启动线程2

经过我不懈的努力下,我发现原因是pygame与threading两个库不兼容!(初步断定)
pygame按键检测在自定义函数下可以正常使用,正常情况下可以使用。
python版本3.7.8
多线程库 threading
pygame版本2.1.2
在这里提出问题,希望解答,谢谢。

将函数前的代码也放入函数,将初始化pygame同时放入两个函数中。
使用函数是,记得全局变量

import pygame, sys, time, threading    #引库”pygame“、”sys“、”time“、“threading”
from pygame.constants import *

def window ():   #创建函数:主程序(为多线程用),命名为“window”

    pygame.init()  # 初始化pygame

    list = []  # 创建列表,命名为“list”
    pygame.display.set_caption("桌面宠物2023春节限定")  # 设置窗口标题
    screen = pygame.display.set_mode((300, 300))  # 设置窗口大小

    # def playSound(musicFile):   #定义播放音乐
    #     sound = pygame.mixer.Sound(musicFile)
    #     sound.play()

    myfont = pygame.font.Font(None, 60)  # 设置字体大小

    bg = pygame.image.load("bg.jpg")  # 加载图片“bg.jpg“命名为”bg“
    mouth_open = pygame.image.load("mouth_open.png")  # 加载图片“mouth_open.png”并命名为”mouth_open“
    mouth_close = pygame.image.load("mouth_close.png")  # 加载图片“mouth_close.png”并命名为”mouth_close“
    screen.blit(bg, (0, 0))  # 显示背景图片“bg.jpg”
    screen.blit(mouth_close, (0, 0))  # 显示背景图片“mouth_close.png”
    pygame.display.update()  # 更新pygame窗口

    while True: #开启循环

        for event in pygame.event.get():    #开启键盘监测

            if event.type == QUIT:   #如果点击窗口的X
                pygame.quit()   #卸载pygame模块
                sys.exit()  #结束程序

            elif event.type == KEYDOWN:  #否则如果键盘按下
                if event.key == K_s: #如果按下“S”键
                    screen.blit(mouth_open, (0, 0)) #显示图片“mouth_open”
                    # pygame.display.update()   #更新pygame窗口
                    time.sleep(3)   #等待3秒
                    screen.blit(mouth_close, (0, 0))    #显示图片“mouth_open”
                    # pygame.display.update()   #更新pygame窗口

        # pygame.display.update() #更新pygame窗口

def refresh (): #创建函数:刷新窗口(为多线程用),命名为“refresh”
    pygame.init()  # 初始化pygame
    while True: #开启循环
        pygame.display.update()  #更新pygame窗口
        time.sleep(0.1) #设置0.1秒刷新一次pygame窗口
        # print("刷新成功!")    告诉我:刷新成功了

thread1 = threading.Thread(target= refresh) #创建多线程,运行函数:“refresh”
thread2 = threading.Thread(target= window)  #创建多线程,运行函数:“window”

thread1.start()   #启动线程1
thread2.start()   #启动线程2