参考文档:http://effbot.org/tkinterbook/python
参考 哔哩哔哩小助手程序json
运行代码:框架
#BiliTkinter import tkinter as tk import requests import json from PIL import Image,ImageTk import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams from BilibiliSpider import headers,JsonParse,WebDownloader,UrlFactory,AnalyseA class BiliWindow: def __init__(self,master,dict_json): self.master = master self.dict_json = dict_json self.getSearch = None #获取搜索输入 self.getEntry = tk.StringVar() #监听entry框中变量值 def create_frame(self,dict_json,picture_lpath,picture_path,picanalysis_lpath,picanalysis_path): #第一框架 frame = tk.Frame(self.master) frame.pack(side=tk.TOP,anchor=tk.N,padx=20,pady=120) ##搜索框 entry = tk.Entry(frame,width=50,highlightthickness=2,textvariable=self.getEntry) entry.pack(side=tk.LEFT,ipady=5) ##按钮 def search(): x = 0 list = [self.tt,self.at,self.st,self.det,self.pt,self.lt,self.cot,self.sht,self.rt,self.dt,self.ct] for i in list: i.delete(1.0,tk.END) self.getSearch = entry.get() #获取搜索值 url = UrlFactory.UrlFactory().getUrlJson(self.getSearch) #从工厂获得连接 r = requests.get(url,headers=headers).json() JsonParse.JsonParse().parseJsonList(self.dict_json,r) #生成视频信息字典 purl = JsonParse.JsonParse().parseJsonImage(r) #获取视频图片连接 pic = requests.get(purl).content #保存图片 with open(picture_lpath,'wb') as f: f.write(pic) for i in dict_json: if x <=11: list[x].insert(tk.END,dict_json[i]) #信息导入text x += 1 p = getTextValue(self.pt) #播放 l = getTextValue(self.lt) #点赞 co = getTextValue(self.cot) #收藏 sh = getTextValue(self.sht) #分享 r = getTextValue(self.rt) #评论 c = getTextValue(self.ct) #硬币 #print(p) #生成数据雷达图 AnalyseA.AnalyseA().draw_analyse(p,l,co,sh,r,c) refactor(picture_lpath,picture_path,220,180) refactor(picanalysis_lpath,picanalysis_path,417,300) self.createImage(picture_path,picanalysis_path) button = tk.Button(frame,text="s",width=3,height=1,command=search) button.pack(padx=10,pady=3) #第二框架 group = tk.Frame(self.master) group.pack() match1 = tk.LabelFrame(group,text="视频信息",padx=5,pady=8) match1.pack(side="left") match2 = tk.LabelFrame(group,text="信息分析图",pady=18) match2.pack() #massage ##picture p = tk.Label(match1,width=30,height=10,bg="LightPink") p.grid(row=0,column=0,rowspan=5,columnspan=3, \ sticky=tk.W+tk.E+tk.N+tk.S) self.pblock = tk.Canvas(p,width=30,height=10,bg="white") ##title t = tk.Label(match1,width=5,height=2,text="名称:") t.grid(row=0,column=3) self.tt = tk.Text(match1,width=10,height=2) self.tt.grid(row=0,column=4,columnspan=2) ##coin c = tk.Label(match1,width=5,height=2,text="硬币数:") c.grid(row=0,column=6) self.ct = tk.Text(match1,width=10,height=1) self.ct.grid(row=0,column=7,columnspan=2) ##sort s = tk.Label(match1,width=5,height=2,text="分类:") s.grid(row=1,column=3) self.st = tk.Text(match1,width=10,height=1) self.st.grid(row=1,column=4,columnspan=2) ##aid a = tk.Label(match1,width=5,height=2,text="AV:") a.grid(row=1,column=6) self.at = tk.Text(match1,width=10,height=1) self.at.grid(row=1,column=7,columnspan=2) ##play p = tk.Label(match1,width=5,height=2,text="播放量:") p.grid(row=2,column=3) self.pt = tk.Text(match1,width=10,height=1) self.pt.grid(row=2,column=4,columnspan=2) ##like l = tk.Label(match1,width=5,height=2,text="点赞数:") l.grid(row=2,column=6) self.lt = tk.Text(match1,width=10,height=1) self.lt.grid(row=2,column=7,columnspan=2) ##share s = tk.Label(match1,width=5,height=2,text="分享数:") s.grid(row=3,column=3) self.sht = tk.Text(match1,width=10,height=1) self.sht.grid(row=3,column=4,columnspan=2) ##collect c = tk.Label(match1,width=5,height=2,text="收藏数:") c.grid(row=3,column=6) self.cot = tk.Text(match1,width=10,height=1) self.cot.grid(row=3,column=7,columnspan=2) ##reply r = tk.Label(match1,width=5,height=2,text="评论数:") r.grid(row=4,column=3) self.rt = tk.Text(match1,width=10,height=1) self.rt.grid(row=4,column=4,columnspan=2) ##danmaku d = tk.Label(match1,width=5,height=2,text="弹幕数:") d.grid(row=4,column=6) self.dt = tk.Text(match1,width=10,height=1) self.dt.grid(row=4,column=7,columnspan=2) ##detail de = tk.Label(match1,width=6,height=2,text="视频简介") de.grid(row=5,column=0) self.det = tk.Text(match1,width=60,height=6) self.det.grid(row=6,column=0,rowspan=3,columnspan=9,pady=5) #radar ##map m = tk.Label(match2,width=60,height=18,bg="LightPink") m.grid(sticky=tk.W+tk.E+tk.N+tk.S,padx=5) self.mblock = tk.Canvas(m,width=60,height=18,bg="white") def createImage(self,picture_path,picanalysis_path): picture = ImageTk.PhotoImage(file=picture_path) self.pblock.create_image(110,97,image=picture) #图片位置 self.pblock.pack(ipadx=92,ipady=91) #画布内距 picanalyse = ImageTk.PhotoImage(file=picanalysis_path) self.mblock.create_image(211,154,image=picanalyse) self.mblock.pack(ipadx=180,ipady=143) self.master.mainloop() #根据自定义大小截取图片 def refactor(start_path,new_path,x,y): img = Image.open(start_path) img = img.resize((x,y),Image.ANTIALIAS) img.save(new_path,quality=96) #获取text中的信息,并以基本数据类型返回 def getTextValue(a): i = int(a.get("0.0","end").replace(" ","")) return i
实际运行效果图:ide