问题描述
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()