前言
同學們在閑暇之余是否喜歡看電影或者電視劇呢?
今天帶領大家使用python制作能免費追劇的桌面軟件。還在等什么?發車了!
先來看看效果如何
全是Python自帶的安裝包,只需安裝了Python即可,不需要安裝模塊
# 正則表達式 import re # 桌面軟件 import tkinter as tk # url解析包 from urllib import parse # 消息盒子包 彈出錯誤信息 import tkinter.messagebox as msgbox # 控制瀏覽器的包 import webbrowser
def __init__(self, width=500, height=300): # 定義類屬性 self.w = width self.h = height
軟件名字
self.title = '視頻解析追劇助手' self.root = tk.Tk(className=self.title)
用戶輸入的視頻地址鏈接
self.url = tk.StringVar()
定義播放源 第三方的播放源
self.v = tk.IntVar() self.v.set(1)
frame_1 = tk.Frame(self.root) frame_2 = tk.Frame(self.root)
group = tk.Label(frame_1, text='播放通道', padx=10, pady=10) tb = tk.Radiobutton(frame_1, text='第一通道', variable=self.v, value=1, width=10, height=3) label = tk.Label(frame_2, text='請輸入視頻鏈接:') entry = tk.Entry(frame_2, textvariable=self.url, highlightcolor='Fuchsia', highlightthickness=1, width=35) play = tk.Button(frame_2, text='播放', font=('楷體', 12), fg='Purple', width=2, height=1, command=self.video_play)
frame_1.pack() frame_2.pack()
確定位置
group.grid(row=0, column=0) tb.grid(row=0, column=1) label.grid(row=0, column=0) entry.grid(row=0, column=1) play.grid(row=0, column=2, ipadx=10, ipady=10)
事件函數 負責打開瀏覽器並且播放電影的函數
def video_play(self): # 第三方播放解析地址 port = 'http://www.wmxz.wang/video.php?url=' # 判斷用戶輸入的鏈接是否合法 if re.match(r'https?:/{2}\w.+$', self.url.get()): ip = self.url.get() ip = parse.quote_plus(ip) # 自動打開瀏覽器 webbrowser.open(port + ip) else: msgbox.showerror(title='錯誤', message='視頻地址輸入有誤, 請重新輸入...')