人类没有孤独的痛苦

一: 爬取b站弹幕图形化界面设计

hello,大家好,又和大家见面啦,我是python学院的热情好市民,用python能做的事情简直如满天星头,人工智能、爬虫、网站开发、数据分析热门行业都可以用python来做,本夜斗小神社则化身为python树洞,一切相关知识都将背化作养分背夜斗小神社这个树洞汲取!喜欢文章的小伙伴可以点点关注哦!绝对不吃亏,绝对不吃亏!

上一篇文章探索了如何爬取bilibili"守护解放西"的弹幕,流程以及思路!这篇文章我想着能不能设计一个图形化界面来实现交互式爬取,那么首先得自己写一个图形化界面吧,开始动手写代码,用的模块是tkinter模块!

需要注意的事项:

图片必须为gif格式的,剩下按照代码及其注释来即可!导入图片, 注意图片的格式只能为gif格式, 不能够盲目修改后缀, 需要用到ps、格式工厂工具转为gif格式!

import tkinter as tk
import webbrowser as wb


def csdn_url():
    wb.open('')


root = tk.Tk()  # 窗口

root.title("爬取b站守护解放西弹幕")  # 窗口名称

root.geometry("500x380")  # 窗口大小

root.resizable(width=True, height=True)  # 窗口可变
# bg为背景,fg为字体颜色,font为字体,width为长,height为高,这里的长和高是字符的长和高,比如height=2,就是标签有2个字符这么高
# 在root窗口上贴一个文本信息为api接口的标签
url_address = tk.Label(root, text="api接口: ", fg='red', font=('宋体', 15), width=12, height=2)
# 将api接口地址标签贴在窗体(110, 80)的位置上
url_address.place(x=70, y=55, anchor="nw")
# 创建输入框----> 用于输入api地url地址
input_url_address = tk.Entry(root, width=30, show=None, font=('Arial', 12), bg='white')
# 布局位置
input_url_address.place(x=175, y=68, anchor='nw')
# 设置一个开始下载按钮
start_load = tk.Button(root, text='点击开始下载', width=12, height=1, command=None)
# 布局下载按钮
start_load.place(x=120, y=130, anchor='nw')
# 点击情况链接
remove_url = tk.Button(root, text="清空api链接", width=12, height=1, command=None)
# 布局清空链接按钮
remove_url.place(x=260, y=130, anchor='nw')
# 创建一块画布
canvas = tk.Canvas(root, bg='green', width=160, height=160)
# 导入图片, 注意图片的格式只能为gif格式, 不能够盲目修改后缀, 需要用到ps、格式工厂工具转为gif格式
# 图片路径填写你自己所需要导入图片的路径
image_gif = tk.PhotoImage(file=r'L:\python package\python小项目\夜斗小神社.gif')
# 放置图片
image = canvas.create_image(82, 2, anchor='n', image=image_gif)
# 放置画布,显示图片
canvas.place(x=60, y=195)
# 布置微信公众号标签
vx_Label = tk.Label(root, text="微信公众号", fg='blue', bg='cyan', font=('宋体', 15), width=23, height=1)
# 将标签放置于窗体上
vx_Label.place(x=250, y=205)
# 布局博客账号
Cn_Label = tk.Button(root, text="点我跳转技术博客", fg='white', bg='green', font=('宋体', 15), width=23, height=1, command=_url)
# 将标签放置于窗体上
Cn_Label.place(x=250, y=280, anchor='nw')
# 顶上方写上标题
Title = tk.Label(root, text="十行代码爬取b站弹幕", fg='orange', bg='aliceblue', font=('宋体', 20), width=18, height=1)
# 将标题布局
Title.place(x=130, y=10, anchor='nw')
root.mainloop()  # 不断刷新窗口

运行代码后的结果则为一个可视化窗口,如下图所示:

python PySide2 悬浮窗 python小窗口_可视化