做一个合并PDF文件的小应用不过分吧。希望可以帮助到你。

主要是因为想合并pdf文件时,软件动不动说什么开个会员啦,页数不能超过5张啦,不啦不啦,我真想给它木大木大木大、欧拉欧拉欧拉、欧拉拉拉拉。
淦,平静一下,这个小小的应用就让我替各位大佬代劳了。
功能实现起来很简单,主要就是想做个GUI界面,锻炼一下自己的布局。
先看看效果图:
在这里插入图片描述
挺寒酸的,但是心里挺美。嘿嘿
具体的代码实现过程就不细讲了,直接贴上来,希望大家能给出一些意见,多谢了。

from PyPDF2 import PdfFileMerger
from tkinter import *
import tkinter.filedialog
from tkinter import messagebox as msgbox
import winsound
import os

root = Tk()
root.title('PDF MERGER _ —— _LittleWhiteDragon_——_仅供学习交流')
root.geometry('490x160+200+300')


def xz1():
    global filename1
    filename1 = tkinter.filedialog.askopenfilename()
    if filename1 is not '':
        l1.config(text=filename1)


def xz2():
    global filename2
    filename2 = tkinter.filedialog.askopenfilename()
    if filename2 is not '':
        l2.config(text=filename2)


Button(root, text='选择PDF文件1', command=xz1, width=18).grid(row=0, column=0)
l1 = Label(root, text='', relief=SUNKEN, width=45)
l1.grid(row=0, column=1)
Button(root, text='选择PDF文件2', command=xz2, width=18).grid(row=1, column=0)
l2 = Label(root, text='', relief=SUNKEN, width=45)
l2.grid(row=1, column=1)
Button(root, text='合并PDF文件输出路径', width=18).grid(row=2, column=0)
l3 = Entry(root, text='', relief=SUNKEN, width=45)
l3.insert(10, '%s/default.pdf' % os.getcwd())
l3.grid(row=2, column=1)


def confirm():
    try:
        if filename1 and filename2:
            winsound.PlaySound('MB_OK', winsound.MB_OK)
            msgbox.showinfo('Confirm Information', 'Confirmed! You can go ahead!')
        else:
            winsound.PlaySound('MB_OK', winsound.MB_OK)
            msgbox.showwarning('Confirm Information', 'Information Invalid! Please check your documents!')
    except NameError:
        winsound.PlaySound('MB_OK', winsound.MB_OK)
        msgbox.showwarning('Confirm Information', 'Information Invalid! Please check your documents!')


Button(root, text='Confirm Information', width=20, command=confirm).grid(row=3, column=0)


def merger():
    main_merger = PdfFileMerger(strict=False)
    try:
        if filename1 and filename2:
            input1 = open('%s' % filename1, 'rb')
            input2 = open('%s' % filename2, 'rb')

            main_merger.append(input1)
            main_merger.append(input2)

            output = open('%s' % l3.get(), 'wb')

            main_merger.write(output)
            msgbox.showinfo('Merge Information', 'Successfully Merged!')
    except:
        pass


Button(root, text='MERGE', command=merger, width=20).grid(row=3, column=1)

Label(root, text='Warning: Do not type the same document name.\nSuggest: click the confirm button first, then merge',
      width=51, fg='red', font=15).grid(row=4, columnspan=2)


root.mainloop()

感兴趣的朋友还可以尝试打包哦。
我这里已经打包好了exe。并压缩了。有需要的朋友可以自行下载使用。
压缩包链接 正于审核。
之后必附上。也可于吾主页资源中相见。
同好同好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ALittleHigh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值