当 运行ning gtts 代码时,一些行(写在 gtts 代码之前)运行 在播放音频之后。在播放音频之前,我想要一些代码行 运行

When running gtts code, some lines (written before gtts code ) run after audio is played. I want some lines of code to run before audio is played

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", padx="6", pady="10")
        play(str(("Congratulations, Your Score is", self.score, "out of 10.")))

此处所有 GUI 部分都在 else 语句中,并且在播放音频后执行。

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