【发布时间】:2016-07-02 22:34:30
【问题描述】:
程序只运行两次。后来,错误发生。我不知道为什么它工作了两次然后就停止了。
import tkinter, sys, pygame
from tkinter import messagebox
from gtts import gTTS
soundfile="file.mp3"
def ex():
sys.exit()
主要问题是:
def read():
t = e.get()
tts = gTTS(text=t, lang="en")
tts.save(soundfile)
pygame.mixer.init(frequency=16000, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load(soundfile)
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.play(0,0.0)
while pygame.mixer.music.get_busy()==True:
continue
pygame.quit()
接下来是按钮的代码。
def clear():
e.delete(0, 'end')
main = tkinter.Tk()
e = tkinter.Entry(main, justify = "center")
l = tkinter.Label(main, text = "Write text")
b1 = tkinter.Button(main, text = "Read", command = read)
b2 = tkinter.Button(main, text = "Clear", command = clear)
b3 = tkinter.Button(main, text = "Exit", command = ex)
所以,我不知道要修复它。
【问题讨论】:
-
启用调试。你得到什么输出?
-
第三次读取后:回溯(最近一次调用最后一次):文件“D:\Programy\Python 3.4.0\lib\tkinter_init_.py”,第 1482 行,在 call 中返回 self.func(*args) 文件“C:\Users\Piotrek\Desktop\Python_Emotiv\StnezatorEnglish.py”,第 13 行,读取 tts.save(soundfile) 文件“D: \Programy\Python 3.4.0\lib\site-packages\gtts-1.1.4-py3.4.egg\gtts\tts.py",第 93 行,用 open(savefile, 'wb') 保存为 f: PermissionError: [Errno 13] Permission denied: 'D:/01_Pulpit/syntezator.mp3'
-
我也有类似@user45193的问题:link
标签: python python-2.7 python-3.x pygame mp3