6,使用 Python 3 和 tkinter 写一个pdf转ppt的程序,有一个文本框2个按钮,点击第一个按钮选择pdf文件并存入文本框中,点击第二个按钮转换该pdf,文件转换成功后保存到当前文件夹
时间: 2023-12-19 10:04:56 浏览: 250
以下是一个基本的实现,您可以根据自己的需求进行修改和完善:
```python
import tkinter as tk
from tkinter import filedialog
import os
import comtypes.client
# 创建窗口
window = tk.Tk()
window.title("PDF转PPT")
window.geometry("400x200")
# 选择文件函数
def choose_file():
file_path = filedialog.askopenfilename(title="选择PDF文件", filetypes=[("PDF Files", "*.pdf")])
path_entry.delete(0, tk.END)
path_entry.insert(0, file_path)
# 转换函数
def convert():
# 获取文件路径
file_path = path_entry.get()
if not os.path.isfile(file_path):
tk.messagebox.showerror("错误", "请选择正确的PDF文件!")
return
# 转换为PPT
ppt_path = os.path.splitext(file_path)[0] + ".pptx"
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
deck = powerpoint.Presentations.Add()
deck.SaveAs(ppt_path, 24) # 24表示PPT格式
deck.Close()
powerpoint.Quit()
tk.messagebox.showinfo("提示", "转换成功!")
# 创建控件
path_label = tk.Label(window, text="选择PDF文件:")
path_label.pack()
path_entry = tk.Entry(window, width=40)
path_entry.pack()
choose_button = tk.Button(window, text="选择文件", command=choose_file)
choose_button.pack()
convert_button = tk.Button(window, text="转换为PPT", command=convert)
convert_button.pack()
# 运行窗口
window.mainloop()
```
需要注意的是,该程序使用了`comtypes`库来操作PowerPoint,因此需要先安装该库。可以使用以下命令进行安装:
```
pip install comtypes
```
阅读全文
相关推荐

















