糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > python实现懒人听书

python实现懒人听书

时间:2018-09-21 13:34:35

相关推荐

python实现懒人听书

import tkinter as tk# 文件选择框的库import tkinter.filedialog as tkf# 智能语音库import pyttsx3# 2、实现选择书籍功能def select_file():global book_textbook_text = ''# 以选择文件对话框path = tkf.askopenfilename()with open(path, 'r', encoding='utf-8') as file:book_text = file.read()# 把读取的内容插入展示text.insert('end', book_text)print(book_text)# 实现听书功能 —— 智能语音库def broad_text():# 初始化book = pyttsx3.init()book.say(book_text)book.runAndWait()# 1、GUI图形用户界面 —— 设置整体布局# 创建图形界面window = tk.Tk()# 设置标题window.title('懒人听书系统')# 修改大小window.geometry('640x480')# 文本框text = tk.Text(window)# 设置GUI的绝对布局 x、y为0 —— 最左边text.place(x=20, y=20, width=600, height=400)# 两个选择按钮open_button = tk.Button(window, text='选择书籍', command=select_file())open_button.place(x=100, y=440, width=150, height=30)open_button = tk.Button(window, text='开始听书', command=broad_text())open_button.place(x=350, y=440, width=150, height=30)# 实现window.mainloop()

运行结果:

如果觉得《python实现懒人听书》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。