蟒蛇/Pygame一旦在我的主循环中调用,如何停止运行特定时间的函数?

问题描述

请善待。这是我在这里的第一篇文章,我不确定我是否以正确的格式/方式发布了我的问题。

我正在制作一个运动训练助手应用程序,它的一个功能,一旦从主循环调用(按下按钮后(我使用的是 pygame )运行特定时间。一旦启动,屏幕冻结直到完成。我如何停止按需执行此功能?我准备好了一个“停止”按钮,但由于屏幕冻结,我无法按下它。 有人可以帮忙吗?

这是函数

def cog_session():
    time.sleep(5)
    Now = time.time()
    timer = 0
    while timer < int(session_time):
        technique = (random.choice(session_list))
        print(technique)
        if technique == "Tan_sau":
            tan_sau.play()
        elif technique == "Bong_sau":
            bong_sau.play()
        elif technique == "Kau_sau":
            kau_sau.play()
        elif technique == "Low_Garn":
            low_garn.play()
        elif technique == "Garn_sau":
            garn_sau.play()
        elif technique == "Kwun_sau":
            kwun_sau.play()
        elif technique == "Lap_sau":
            lap_sau.play()
        elif technique == "Pak_sau":
            pak_sau.play()
        elif technique == "Biu_sau":
            biu_sau.play()
        elif technique == "Gum_sau":
            gum_sau.play()
        
        time.sleep(cooldown + (random.randint(1,4)))
        end = time.time()
        timer = round(end-Now)
        print(timer)
    return

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)