
Python,速成心法
敲代码,查资料,问Ai
练习,探索,总结,优化

★★★★★博文创作不易,源码使用过程中,如有疑问的地方,欢迎大家指正留言交流。喜欢的老铁可以多多点赞+收藏分享+置顶,小红牛在此表示感谢。★★★★★
------★Python练手项目源码★------
Python项目104:窗口探测系统1.0(tkinter+pywin32)
Python项目102:Tkinter实现电脑屏幕锁屏,输入正确密码才能解锁
Python项目99:Tkinter十六进制颜色对照表2.0(140种颜色)
Python项目94:全球疫情模拟数据可视化大屏(dash+plotly+pandas)
Python项目91:绘制红楼梦人物关系图(NetworkX+Matplotlib)
Python项目89:NetworkX最短路径规划(城市交通)
Python项目88:文件备份与压缩系统2.0(tkinter+shutil+zipfile)
Python项目86:增强版画板2.0(tk.Canvas)
Python项目81:Excel工作表批量重命名工具1.0(tkinter+openpyxl)
Python项目78:学生成绩分析系统(Tkinter+SQLite3)
Python项目77:模拟炒股训练系统3.0(Mplfinance+tkinter)
Python项目76:员工排班表系统1.0(tkinter+sqlite3+tkcalendar)
Python项目74:多线程数据可视化工具2.0(tkinter+matplotlib+mplcursors)
Python项目73:自动化文件备份系统1.0(tkinter)
Python项目源码71:药品管理系统1.0(tkinter+sqlite3)
Python项目源码69:Excel数据筛选器1.0(tkinter+sqlite3+pandas)
Python项目源码63:病历管理系统1.0(tkinter+sqlite3+matplotlib)
Python源码62:酒店住房管理系统1.0(tkinter+sqlite3)
Python项目源码57:数据格式转换工具1.0(csv+json+excel+sqlite3)
Python项目源码56:食堂饭卡管理系统1.0(tkinter+splite3)
Python项目源码54:员工信息管理系统2.0(tkinter+sqlite3)
Python项目源码52:模拟银行卡系统1.0(账户管理、存款、取款、转账和交易记录查询)
Python项目源码50:理发店会员管理系统1.0(tkinter+sqlite3)
Python项目源码48:正则表达式调试工具3.0(tkinter+re+requests)
Python项目源码44:图书管理系统1.0(tkinter+sqlite3)
Python项目源码42:仓库商品管理系统1.0(tkinter+sqlite3+Excel)
Python项目源码40:字符串处理工具(tkinter+入门练习)
Python项目源码39:学生积分管理系统1.0(命令行界面+Json)
Python项目源码35:音乐播放器2.0(Tkinter+mutagen)
Python项目源码33:待办事项列表应用2.0(命令行界面+Json+类)
Python项目32:订单销售额管理系统1.0(Tkinter+CSV)
Python项目源码29:学生缴费管理系统(Tkinter+CSV)
Python项目28:设计日志管理系统2.0(Tkinter+Json)
功能简介:本工具可按照您选择的顺序,这样你可以调整多个pdf的前后顺序,将多个 PDF 文件合并为一个 PDF 文件。合并后的文件保存在程序所在目录,文件名可自定义。
pip install pypdf操作步骤

↓ 完整源码如下 ↓
# -*- coding: utf-8 -*-# @Author : 小红牛# 微信公众号:wdPythonimport tkinter as tkfrom tkinter import filedialog, messageboxfrom pypdf import PdfWriter, PdfReaderimport osclass PdfMergerApp:def __init__(self, root):self.root = rootroot.title("PDF 合并工具——按列表先后顺序合并")root.geometry("800x500")root.resizable(False, False)self.file_list = []# 界面控件tk.Label(root, text="依次选择 PDF 文件,合并的时候,按列表先后顺序合并", font=("Arial", 10)).pack(pady=5)# 文件名输入框name_frame = tk.Frame(root)name_frame.pack(pady=5)tk.Label(name_frame, text="保存文件名(不含扩展名):").pack(side=tk.LEFT)self.filename_var = tk.StringVar()self.filename_var.set("merged")tk.Entry(name_frame, textvariable=self.filename_var, width=20).pack(side=tk.LEFT, padx=5)btn_frame = tk.Frame(root)btn_frame.pack(pady=5)tk.Button(btn_frame, text="📄 添加 PDF", command=self.add_files, width=12).pack(side=tk.LEFT, padx=5)tk.Button(btn_frame, text="❌ 删除选中", command=self.delete_selected, width=12).pack(side=tk.LEFT, padx=5)tk.Button(btn_frame, text="🗑️ 清空列表", command=self.clear_list, width=12).pack(side=tk.LEFT, padx=5)tk.Button(btn_frame, text="🔗 合并", command=self.merge_pdfs, width=12).pack(side=tk.LEFT, padx=5)# pdf列表self.listbox = tk.Listbox(root, selectmode=tk.EXTENDED, height=12)self.listbox.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)self.status_var = tk.StringVar()self.status_var.set("当前无文件")tk.Label(root, textvariable=self.status_var, fg="blue").pack(pady=5)def add_files(self):files = filedialog.askopenfilenames(title="选择 PDF 文件",filetypes=[("PDF 文件", "*.pdf")])if not files:returnfor f in files:if f not in self.file_list:self.file_list.append(f)self.listbox.insert(tk.END, os.path.basename(f))self.update_status()def delete_selected(self):selected = self.listbox.curselection()if not selected:messagebox.showinfo("提示", "请先选中要删除的文件")returnfor idx in reversed(selected):del self.file_list[idx]self.listbox.delete(idx)self.update_status()def clear_list(self):if self.file_list and messagebox.askyesno("确认", "清空所有文件?"):self.file_list.clear()self.listbox.delete(0, tk.END)self.update_status()def update_status(self):count = len(self.file_list)self.status_var.set(f"已选 {count} 个文件" if count else "当前无文件")def merge_pdfs(self):if not self.file_list:messagebox.showwarning("提示", "请先添加 PDF 文件")returnfilename = self.filename_var.get().strip()if not filename:filename = "merged"# 自动补 .pdf 扩展名(若用户未输入)if not filename.lower().endswith('.pdf'):filename += '.pdf'output_path = os.path.join(os.getcwd(), filename)writer = PdfWriter()total = len(self.file_list)for i, filepath in enumerate(self.file_list, 1):self.status_var.set(f"处理中: {os.path.basename(filepath)} ({i}/{total})")self.root.update()try:reader = PdfReader(filepath)for page in reader.pages:writer.add_page(page)except Exception as e:messagebox.showerror("错误", f"读取文件失败:{e}")returntry:with open(output_path, "wb") as f:writer.write(f)self.status_var.set(f"✅ 合并完成 → {output_path}")messagebox.showinfo("完成", f"已保存到:{output_path}")except Exception as e:messagebox.showerror("错误", f"保存失败:{e}")if __name__ == "__main__":root = tk.Tk()app = PdfMergerApp(root)root.mainloop()
完毕!!感谢您的收看
------★★历史博文集合★★------
