[PySide6]使用PyPDF2与PySide6制作一个PDF加密小工具

  1. 环境配置
    python 3.10
    PyPDF2 1.26.0
    PySide6 6.2.3
    IDE PyCharm社区版

  2. 界面设计
    Qt设计师路径在PySide6目录下,我的路径为: \Lib\site-packages\PySide6
    使用 Qt设计师拖拉拽一个界面
    在这里插入图片描述
    将ui文件保存到python项目的ui文件夹中,项目结构如图所示
    在这里插入图片描述
    main_window.ui是ui文件
    main.py是入口文件
    main_window.py是界面相关逻辑文件
    pdf_encrypt.py是加密pdf的文件

  3. 代码
    pdf_encrypt.py
    ‘# type:PdfFileReader’ 是做类型说明,不然后面的pdf_reader没有方法提示,就很*疼

from PyPDF2 import PdfFileReader, PdfFileWriter

"""
@filename: /pdf_encrypt.py
@Author: 四十
@createtime: 2022/3/19-20:35
@Description: ... 
"""


def encrypt(path, pwd):
    try:
        pdf_reader = PdfFileReader(stream=path, strict=False)  # type:PdfFileReader
    except Exception as e:
        return e
    filepath = path[:path.rfind("/")] + "/"
    filename = path.split("/")[-1].split(".")
    file_suffix = filename[1]
    if file_suffix != "pdf":
        return "Please select a pdf file!"
    filename = filename[0] + "_pwd.pdf"

    pdf_writer = PdfFileWriter()  # type:PdfFileWriter
    try:
        for page in range(pdf_reader.<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Develop more dynamic and robust GUI applications using PySide, an open source cross-platform UI framework About This Book Designed for beginners to help you get started with GUI application development Develop your own applications by creating customized widgets and dialogs Written in a simple and elegant structure so you easily understand how to program various GUI components Who This Book Is For This book is written for Python programmers who want to learn about GUI programming. It is also suitable for those who are new to Python but are familiar with object-oriented programming. What You Will Learn Program GUI applications in an easy and efficient way Download and install PySide, a cross-platform GUI development toolkit for Python Create menus, toolbars, status bars, and child windows Develop a text editor application on your own Connect your GUI to a database and manage it Execute SQL queries by handling databases In Detail Elegantly-built GUI applications are always a massive hit among users. PySide is an open source software project that provides Python bindings for the Qt cross-platform UI framework. Combining the power of Qt and Python, PySide provides easy access to the Qt framework for Python developers and also acts as an excellent rapid application development platform. This book will take you through everything you need to know to develop UI applications. You will learn about installing and building PySide in various major operating systems as well as the basics of GUI programming. The book will then move on to discuss event management, signals and slots, and the widgets and dialogs available with PySide. Database interaction and manipulation is also covered. By the end of this book, you will be able to program GUI applications efficiently and master how to develop your own applications and how to run them across platforms. Style and approach This is an accessible and practical guide to developing GUIs for Python applications. Table of Contents Ch

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值