python3制作一款搜索软件

用python打造一款搜索软件,可以助各位读者快速找到想要的资源,废话不多说,直接上代码,首先导入相应的模块:

import random
import webbrowser
import re
from urllib import parse
from tkinter import *
from tkinter import ttk
import win32api
import win32con

接着设置需要的全局变量:

# 全局变量
colors = ['Snow', 'Teal', 'Tan', 'Cyan', 'DarkGray']

shi_url_list = ['无', 'https://www.ciliwang.club/list.html?keyword=',
                'https://biedian.me/search?source=%E7%A3%81%E5%8A%9B%E7%8E%8B&k=',
                'http://newbtspread.org/', 'http://www.sosobt8.com/s/',
                'https://www.btdad.com/search-', 'http://f.cili001.com/index/index?c=&k=',
                'https://lemencili1.xyz/search?keyword=', 'https://www.zhongzilou.com/list_ctime/',
                'https://www.ciliwiki.com/search/', 'https://zooqle.com/search?q=',
                'https://www.torrentkitty.tv/search/',
                'https://ibit.to/torrent-search/']

ping_url_list = ['无', 'http://btlibrarys.com/', 'http://btdiggcn.ws/', 'https://tuzibt5.godht.top/',
                 'http://cili.search.qinggl.com/']

li_list = ['重新选择', '复制内容', '粘贴内容', '退出程序']

然后编辑程序的主函数:

def get_result():
    # 视频解析
    if v.get() == 1:
        url = str(entry.get())
        # print(url)
        port = shi_url_list[wan.get()]
        if wan.get() == 1:
            url_list = port + url + "&sort=hot"
        elif wan.get() == 2:
            url_list = port + url + "&s=default&p=1"
        elif wan.get() == 3:
            url_list = port + url + "/1-0-0/"
        elif wan.get() == 4:
            url_list = port + url + "/1.html"
        elif wan.get() == 5:
            url_list = port + url + "-0-0-1.html"
        elif wan.get() == 6:
            url_list = port + url + ""
        elif wan.get() == 7:
            url_list = port + url + ""
        elif wan.get() == 8:
            url_list = port + url + "/1"
        elif wan.get() == 9:
            url_list = port + url + "-1.html"
        elif wan.get() == 10:
            url_list = port + url + ""
        elif wan.get() == 11:
            url_list = port + url + "/"
        elif wan.get() == 12:
            url_list = port + url + "/"
        wb = webbrowser.open(url_list)


def get_result_1():
    # 视频网站
    if v.get() == 2:
        port = ping_url_list[shi.get()]
        # print(port)
        # exit()
        wb = webbrowser.open(port)


def get_delete():
    entry.delete(0, END)


def get_copy():
    win32api.keybd_event(17, 0, 0, 0)  # ctrl键位码是17
    win32api.keybd_event(67, 0, 0, 0)  # c键位码是67
    win32api.keybd_event(67, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
    win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)


def get_paste():
    win32api.keybd_event(17, 0, 0, 0)  # ctrl键位码是17
    win32api.keybd_event(86, 0, 0, 0)  # v键位码是86
    win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
    win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)


# 设置背景颜色
def get_background():
    wo = Yan.get()
    # root.configure(background = colors[wo])
    root.config(bg=colors[wo])


# 设置 视频解析和视频网站 两个按钮的开关
def get_choose():
    # 选择种子网站
    if v.get() == 2:
        for xu in range(0, 3):
            for lie in range(1, 5):
                button_0 = Radiobutton(root, text=str(lie + xu * 4) + '-' + '通道', font=("隶书", 20), variable=wan,
                                       value=(lie + xu * 4), bg='white', activeforeground='gold',
                                       activebackground='green', fg='black', state='disabled')
                button_0.place(x=int(lie - 1) * 200 + 250, y=200 + 50 * xu)

        for di in range(1, 5):
            button_1 = Radiobutton(root, text='种子网站-' + str(di), font=("隶书", 20), variable=shi, value=di, bg='white',
                                   activeforeground='gold', activebackground='green', fg='black', state='normal')
            level_1 = 200 * di
            button_1.place(x=level_1, y=360)

    # 选择种子搜索
    if v.get() == 1:

        for xu in range(0, 3):
            for lie in range(1, 5):
                button_0 = Radiobutton(root, text=str(lie + xu * 4) + '-' + '通道', font=("隶书", 20), variable=wan,
                                       value=(lie + xu * 4), bg='white', activeforeground='gold',
                                       activebackground='green', fg='black', state='normal')
                button_0.place(x=int(lie - 1) * 200 + 250, y=200 + 50 * xu)

        for di in range(1, 5):
            button_1 = Radiobutton(root, text='种子网站-' + str(di), font=("隶书", 20), variable=shi, value=di, bg='white',
                                   activeforeground='gold', activebackground='green', fg='black', state='disabled')
            level_1 = 200 * di
            button_1.place(x=level_1, y=360)

最后进行GUI界面的布局:

# 绘制窗口
root = Tk()
# 设置标题
root.title('种子搜索工具')
# 窗口的位置和大小
root.geometry('1043x680+260+50')
# 设置窗口是否可以变化长宽,默认可变
root.resizable(width=False, height=False)

pic = PhotoImage(file='zhong_1.gif')
lable14 = Label(root, image=pic)
lable14.place(x=840, y=0)

lable1 = Label(root, text=' 种子搜索工具', font=('微软雅黑', 30), fg='black', bg='white')
lable1.place(x=400, y=0)

lable12 = Label(root, text='  背景颜色:', font=('微软雅黑', 25), fg='black', bg='white')
lable12.place(x=0, y=435)

lable13 = Label(root, text=' 搜索通道选择:', font=('微软雅黑', 25), fg='black', bg='white')
lable13.place(x=0, y=200)

lable15 = Label(root, text='请输入搜索内容:', font=('微软雅黑', 20), fg='black', bg='white')
lable15.place(x=0, y=70)

lable16 = Label(root, text='(选择种子搜索,将要搜索的内容粘贴到输入框内再点击 , 如无法打开网站请将网址复制到谷歌浏览器里打开)', font=('微软雅黑', 15), fg='blue', bg='white')
lable16.place(x=0, y=150)

lable17 = Label(root, text='解析的网站:', font=('微软雅黑', 25), fg='black', bg='white')
lable17.place(x=0, y=350)

lable18 = Label(root, text='(选择种子网站直接点击,到网站再填入搜索内容)', font=('微软雅黑', 15), fg='blue', bg='white')
lable18.place(x=0, y=400)

# 输入控件,state设置只允许可读
entry = Entry(root, font=('微软雅黑', 20), width=65, bg='white')
entry.place(x=0, y=110)

v = IntVar()
v.set(1)
# v.set(3)  # 如果1,那么简单被默认选中
# 如果3,那么正常被默认选中
# 如果4,那么复制被默认选中

button1 = Radiobutton(root, text='种子搜索', font=("隶书", 15), bg='white', variable=v, activeforeground='gold',
                      activebackground='green', value=1, command=get_choose)
button1.place(x=450, y=65)

button2 = Radiobutton(root, text='种子网站', font=("隶书", 15), bg='white', variable=v, activeforeground='gold',
                      activebackground='green', value=2, command=get_choose)
button2.place(x=650, y=65)

button3 = Button(root, text='开始搜索', font=("隶书", 35), bg='green', activeforeground='gold', activebackground='Snow',
                 command=get_result)
button3.place(x=10, y=500, width=520)

button4 = Button(root, text='打开网站', font=("隶书", 35), bg='green', activeforeground='gold', activebackground='Snow',
                 command=get_result_1)
button4.place(x=530, y=500, width=500)

# 最下面的四个按钮
button5 = Button(root, text=li_list[0], font=("隶书", 30), bg='Snow', activeforeground='gold', activebackground='green',
                 command=get_delete)
button5.place(x=10, y=600)

button6 = Button(root, text=li_list[1], font=("隶书", 30), bg='Snow', activeforeground='gold', activebackground='green',
                 command=get_copy)
button6.place(x=290, y=600)

button7 = Button(root, text=li_list[2], font=("隶书", 30), bg='Snow', activeforeground='gold', activebackground='green',
                 command=get_paste)
button7.place(x=570, y=600)

button8 = Button(root, text=li_list[3], font=("隶书", 30), bg='Snow', activeforeground='gold', activebackground='green',
                 command=root.quit)
button8.place(x=850, y=600)

# 背景颜色按钮
Yan = IntVar()
Yan.set(0)
wo = Yan.get()
root.configure(background=colors[wo])
for col in range(5):
    button0 = Radiobutton(root, text=colors[col], font=("隶书", 20), variable=Yan, value=col, bg='white', fg='black',
                          activeforeground='gold', activebackground='green', command=get_background)
    level = 250 + 130 * col
    button0.place(x=level, y=440)

# 搜索通道按钮
wan = IntVar()
wan.set(1)
wang = shi_url_list[wan.get()]
for xu in range(0, 3):
    for lie in range(1, 5):
        button_0 = Radiobutton(root, text=str(lie + xu * 4) + '-' + '通道', font=("隶书", 20), variable=wan,
                               value=(lie + xu * 4), bg='white', activeforeground='gold', activebackground='green',
                               fg='black')
        button_0.place(x=int(lie - 1) * 200 + 250, y=200 + 50 * xu)

# 搜索网站按钮
shi = IntVar()
for di in range(1, 5):
    button_1 = Radiobutton(root, text='种子网站-' + str(di), font=("隶书", 20), variable=shi, value=di, bg='white',
                           activeforeground='gold', activebackground='green', state='disabled', fg='black')
    level_1 = 200 * di
    button_1.place(x=level_1, y=360)

# 窗口的循环显示
root.mainloop()

这个代码的编写时间较久远,有些通道可能失效了,但大多通道都是可以使用的,读者有不懂的地方可以私信博主或在下方进行评论,博主会在第一时间进行答复,我是活动的笑脸。

  • 6
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值