运行gtts代码时某些行在 gtts 代码之前编写在播放音频后运行我希望在播放音频之前运行一些代码行

问题描述

    def play(audio):
        sound = gTTS(audio)
        sound.save('sound.mp3')
        playsound('sound.mp3')

    def isCorrect(self,n):  # checking whether option clicked is correct or not and updating info
        if n == self.anspos:
            self.score = self.score + 1  # increasing score if correct
        self.progress = self.progress + 1  # increasing progress
        p.update()
        if self.progress != 10:
            p.newQues()  # going for next question if 10 questions are not yet completed
        else:
            Prog.grid_forget(),score.grid_forget(),Q.grid_forget()  # removing unwanted labels and button
            A.grid_forget(),B.grid_forget(),C.grid_forget(),D.grid_forget()
            Result.grid(row="0",columnspan="2",pady="6",padx="10")  # adding result label
            final.set(("Congratulations!!,","Your","score","is",self.score,"/","10"))  # setting result in gui.
            Quit.grid(row="1",column="1",padx="6",pady="10"),Restart.grid(row="1",column="0",pady="10")
            play(str(("Congratulations,Your score is","out of 10.")))

这里所有的 GUI 部分都在 else 语句中,并且在音频播放后执行

解决方法

在播放音频之前添加 window.update() 即可。 窗口是 tkinter.Tk()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...