吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3186|回复: 38
收起左侧

[Python 原创] 一键套红小程序

  [复制链接]
w3812247 发表于 2023-4-25 09:56
最近隔壁老王换了个部门,每天忙于套红头,于是他问我有没有能一键套红的小工具,在他答应请我吃一顿海底捞以后,我给他写了一个小工具,小工具用python开发的,没多少行代码。有需要的可以自己改改。 动画1.gif

[Python] 纯文本查看 复制代码
from docxtpl import DocxTemplate
from tkinter import *
from tkinter.ttk import *
import time
import os, sys
class WinGUI(Tk):
    widget_dic = dict()

    def __init__(self):
        super().__init__()
        self.__win()
        self.widget_dic["tk_label_num"] = self.__tk_label_num(self)
        self.widget_dic["tk_label_subject"] = self.__tk_label_subject(self)
        self.widget_dic["tk_label_inscription"] = self.__tk_label_inscription(self)
        self.widget_dic["tk_label_strdate"] = self.__tk_label_strdate(self)
        self.widget_dic["tk_label_context"] = self.__tk_label_context(self)
        self.widget_dic["tk_input_num"] = self.__tk_input_num(self)
        self.widget_dic["tk_input_subject"] = self.__tk_input_subject(self)
        self.widget_dic["tk_input_inscription"] = self.__tk_input_inscription(self)
        self.widget_dic["tk_input_strdate"] = self.__tk_input_strdate(self)
        self.widget_dic["tk_text_context"] = self.__tk_text_context(self)
        self.widget_dic["tk_button_lglldrmn"] = self.__tk_button_lglldrmn(self)
        self.widget_dic["tk_label_lglle6t3"] = self.__tk_label_lglle6t3(self)
        self.widget_dic["tk_button_default"] = self.__tk_button_default(self)
        self.widget_dic["tk_button_openmoban"] = self.__tk_button_openmoban(self)
    def __win(self):
        self.title("一键套红")
        # 设置窗口大小、居中
        width = 600
        height = 500
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        self.resizable(width=False, height=False)

        # 自动隐藏滚动条

    def scrollbar_autohide(self, bar, widget):
        self.__scrollbar_hide(bar, widget)
        widget.bind("<Enter>", lambda e: self.__scrollbar_show(bar, widget))
        bar.bind("<Enter>", lambda e: self.__scrollbar_show(bar, widget))
        widget.bind("<Leave>", lambda e: self.__scrollbar_hide(bar, widget))
        bar.bind("<Leave>", lambda e: self.__scrollbar_hide(bar, widget))

    def __scrollbar_show(self, bar, widget):
        bar.lift(widget)

    def __scrollbar_hide(self, bar, widget):
        bar.lower(widget)

    def __tk_label_num(self, parent):
        label = Label(parent, text="文号", anchor="center")
        label.place(x=60, y=20, width=50, height=30)
        return label

    def __tk_label_subject(self, parent):
        label = Label(parent, text="标题", anchor="center")
        label.place(x=60, y=60, width=50, height=30)
        return label

    def __tk_label_inscription(self, parent):
        label = Label(parent, text="落款", anchor="center")
        label.place(x=60, y=100, width=50, height=30)
        return label

    def __tk_label_strdate(self, parent):
        label = Label(parent, text="日期", anchor="center")
        label.place(x=60, y=140, width=50, height=30)
        return label

    def __tk_label_context(self, parent):
        label = Label(parent, text="内容", anchor="center")
        label.place(x=60, y=180, width=50, height=30)
        return label

    def __tk_input_num(self, parent):
        ipt = Entry(parent)
        ipt.place(x=120, y=20, width=389, height=30)
        return ipt

    def __tk_input_subject(self, parent):
        ipt = Entry(parent)
        ipt.place(x=120, y=60, width=389, height=30)
        return ipt

    def __tk_input_inscription(self, parent):
        ipt = Entry(parent)
        ipt.place(x=120, y=100, width=389, height=30)
        return ipt

    def __tk_input_strdate(self, parent):
        ipt = Entry(parent)
        ipt.place(x=120, y=140, width=389, height=30)
        return ipt

    def __tk_text_context(self, parent):
        text = Text(parent)
        text.place(x=120, y=180, width=389, height=203)

        return text

    def __tk_button_lglldrmn(self, parent):
        btn = Button(parent, text="开始套红")
        btn.place(x=130, y=420, width=341, height=30)
        return btn

    def __tk_label_lglle6t3(self, parent):
        label = Label(parent, text="套红完毕的文件生成在程序所在的文件夹", anchor="center")
        label.place(x=60, y=460, width=482, height=30)
        return label

    def __tk_button_default(self, parent):
        btn = Button(parent, text="默认值")
        btn.place(x=60, y=420, width=63, height=30)
        return btn

    def __tk_button_openmoban(self, parent):
        btn = Button(parent, text="打开模版")
        btn.place(x=480, y=420, width=62, height=30)
        return btn
class Win(WinGUI):
    def __init__(self):
        super().__init__()
        self.__event_bind()

    def taohong(self, evt):
        base_path = self.base_path('')
        tpl = DocxTemplate(base_path+'moban.docx')
        num = self.widget_dic["tk_input_num"].get()
        subject = self.widget_dic["tk_input_subject"].get()
        context = self.widget_dic["tk_text_context"].get(1.0, END)
        inscription = self.widget_dic["tk_input_inscription"].get()
        strdate = self.widget_dic["tk_input_strdate"].get()
        strlist = {"num": num, "subject": subject, "context": context, "inscription": inscription, "strdate": strdate}
        tpl.render(strlist)
        tpl.save(subject+".docx")
        self.widget_dic["tk_label_lglle6t3"]["text"]= "套红完毕!"
        os.system('start ' +subject+ '.docx')

    def default(self, evt):
        nowtime = time.localtime(time.time())
      
        self.widget_dic["tk_input_num"].insert(0,"XXXXX党总支委发〔"+str(nowtime[0])+"〕1号")
        self.widget_dic["tk_input_inscription"].insert(0,"XXXXXXX有限公司总支部委员会")
        self.widget_dic["tk_input_strdate"].insert(0,str(nowtime[0])+"年"+str(nowtime[1])+"月"+str(nowtime[2])+"日")
        print(self.base_path(''))

    def openmoban(self, evt):

        base_path = self.base_path('')
        os.system('start '+base_path+ 'moban.docx')

    def __event_bind(self):
        self.widget_dic["tk_button_lglldrmn"].bind('<Button-1>', self.taohong)
        self.widget_dic["tk_button_default"].bind('<Button-1>', self.default)
        self.widget_dic["tk_button_openmoban"].bind('<Button-1>', self.openmoban)


    def base_path(self,path):
        if getattr(sys, 'frozen', None):
            basedir = sys._MEIPASS
        else:
            basedir = os.path.dirname(__file__)
        return os.path.join(basedir, path)



if __name__ == "__main__":
    win = Win()
    win.mainloop()


模版和成品我放到蓝奏里了。
https://wwox.lanzout.com/b0421pj8f
密码:4ro7

免费评分

参与人数 6吾爱币 +11 热心值 +5 收起 理由
wushaominkk + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
wr4tt + 1 + 1 谢谢@Thanks!
SVIP008 + 1 感觉很有用,确实实用!
woyucheng + 1 + 1 谢谢@Thanks!
zwqlon1978 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
jtjt68 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

baishuihao 发表于 2023-4-25 09:59
下载地址里面是空的
zwqlon1978 发表于 2023-4-25 10:11
 楼主| w3812247 发表于 2023-4-25 09:59
baishuihao 发表于 2023-4-25 10:06
w3812247 发表于 2023-4-25 09:59
更新了一下,再试试

有了
辛苦了我下载收藏
henryz 发表于 2023-4-25 10:10
感谢分享
q6346753 发表于 2023-4-25 10:16
谢谢分享好东西
zengzw 发表于 2023-4-25 10:20
很不错,非常方便,谢谢分享
oxding 发表于 2023-4-25 10:25
请问是用的什么打包库 ,会不会出现闪退
cnct2021 发表于 2023-4-25 10:35
你这是应对清编的及时雨啊
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 21:49

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表