|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# 作者:闲欢 公众号:Python技术 |
| 4 | + |
| 5 | +from tkinter import * |
| 6 | + |
| 7 | +# str = '链接: https://pan.baidu.com/s/1ctcXiZymWst2NC_JPDkr4Q 提取码: j1ub 复制这段内容后打开百度网盘手机App,操作更方便哦' |
| 8 | +class panTool: |
| 9 | + def __init__(self, init_window_name): |
| 10 | + self.init_window_name = init_window_name |
| 11 | + |
| 12 | + def extractData(self): |
| 13 | + str = self.init_data_text.get(1.0, END) |
| 14 | + url_pattern = 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' |
| 15 | + code_pattern = '(?<=提取码: )[0-9a-z]{4}' |
| 16 | + url_regex = re.compile(url_pattern) |
| 17 | + code_regex = re.compile(code_pattern) |
| 18 | + # 输出到界面 |
| 19 | + self.link_data_text.delete(1.0, END) |
| 20 | + self.code_data_text.delete(1.0, END) |
| 21 | + self.link_data_text.insert(1.0, url_regex.findall(str)[0]) |
| 22 | + self.code_data_text.insert(1.0, code_regex.findall(str)[0]) |
| 23 | + return |
| 24 | + |
| 25 | + def draw_window(self): |
| 26 | + self.init_window = Tk() # 实例化出一个父窗口 |
| 27 | + self.init_window.title("百度网盘提取链接工具_v1.0") # 窗口名 |
| 28 | + self.init_window.geometry('800x300+10+10') |
| 29 | + # 源信息 |
| 30 | + self.init_data_label = Label(self.init_window, text="复制的提取信息") |
| 31 | + self.init_data_label.grid(row=0, column=0) |
| 32 | + self.init_data_text = Text(self.init_window, width=100, height=5, borderwidth=1, relief="solid") # 原始数据录入框 |
| 33 | + self.init_data_text.grid(row=1, column=0, columnspan=10) |
| 34 | + |
| 35 | + # 按钮 |
| 36 | + self.str_trans_button = Button(self.init_window, text="提取", width=10, height=2, bg="blue", |
| 37 | + command=self.extractData) # 调用内部方法 加()为直接调用 |
| 38 | + self.str_trans_button.grid(row=2, column=2) |
| 39 | + |
| 40 | + # 链接 |
| 41 | + self.link_data_label = Label(self.init_window, width=10, text="链接") |
| 42 | + self.link_data_label.grid(row=3, column=0, columnspan=1) |
| 43 | + self.link_data_text = Text(self.init_window, width=60, height=2, borderwidth=1, relief="solid") |
| 44 | + self.link_data_text.grid(row=3, column=1, columnspan=6) |
| 45 | + |
| 46 | + # 提取码 |
| 47 | + self.code_data_label = Label(self.init_window, width=10, text="提取码") |
| 48 | + self.code_data_label.grid(row=3, column=7, columnspan=1) |
| 49 | + self.code_data_text = Text(self.init_window, width=20, height=2, borderwidth=1, relief="solid") |
| 50 | + self.code_data_text.grid(row=3, column=8, columnspan=2) |
| 51 | + |
| 52 | +def gui_start(): |
| 53 | + # 实例化出一个父窗口 |
| 54 | + init_window = Tk() |
| 55 | + tool = panTool(init_window) |
| 56 | + # 设置根窗口默认属性 |
| 57 | + tool.draw_window() |
| 58 | + # 父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示 |
| 59 | + init_window.mainloop() |
| 60 | + |
| 61 | +gui_start() |
| 62 | + |
0 commit comments