1.2.2 UI设计
我们用到的是中的第三方库 , 可以很容易的实现简单的UI设计 。涉及到的操作就是控件的布局、鼠标点击的响应事件、控件中数据的获取 , 都是一些比较简单的操作 。这里简单放一下我设计的结果(设计的比较简陋 , 因为俺也是现学的这东西 , 不是很懂那些高级控件) , 具体操作我们后面说 。
【Python基于网络爬虫的商品询价系统的设计与实现】import tkinter as tkfrom tkinter import ttkimport tkinter.messageboxfrom GoodsList import GoodsListfrom Goods import Goodsfrom DBConnection import DBConnectionclass GUI:#用于存放商品信息goodsinfo = []#主窗口window = tk.Tk()#框架划分frm_t = tk.Frame(window, width=1000, height=300).pack()frm_b = tk.Frame(window, width=1000, height=600).pack()frm_d = tk.Frame(window, width=1000, height=100).pack()#平台选择tm_var = tk.IntVar()jd_var = tk.IntVar()pdd_var = tk.IntVar()c1 = tk.Checkbutton(frm_t, text='天猫', variable=tm_var, onvalue=http://www.kingceram.com/post/1, offvalue=0)c2 = tk.Checkbutton(frm_t, text='京东', variable=jd_var, onvalue=1, offvalue=0)c3 = tk.Checkbutton(frm_t, text='拼多多', variable=pdd_var, onvalue=1, offvalue=0)#获取爬取商品数量dp_var = tk.IntVar()dp_en = tk.Entry(frm_t, textvariable=dp_var, width=3)#获取搜索关键词goods_var = tk.StringVar()goods_en = tk.Entry(frm_t, textvariable=goods_var, width=10)#排序方式sort_var = tk.IntVar()ch1 = tk.Radiobutton(frm_b, text='默认排序', variable=sort_var, value=1)ch2 = tk.Radiobutton(frm_b, text='价格升序', variable=sort_var, value=2)ch3 = tk.Radiobutton(frm_b, text='价格倒序', variable=sort_var, value=3)# 获取序号num_var = tk.StringVar()num_en = tk.Entry(frm_t, textvariable=num_var, width=50)#表格tree = ttk.Treeview(frm_d, columns=['1', '2', '3', '4', '5', '6', '7', '8'], show='headings', height=25)#表格滚动条VScroll1 = ttk.Scrollbar(tree, orient='vertical', command=tree.yview)#这个按钮后面在函数中需要变动 , 所以设为全局变量comfirm3 = tk.Button(frm_t, text='加入关注',width=20)#获取信息def getInfo(self):self.comfirm3.config(text = '加入关注',command=self.addtoDB)self.goodsinfo.clear()tm = self.tm_var.get()jd = self.jd_var.get()pdd = self.pdd_var.get()number = self.dp_var.get()keyword = self.goods_var.get()if not tm and not jd and not pdd:tk.messagebox.showinfo(title='提示', message='您未选取任何平台')returncheck_numls=[]for i in range(60):check_numls.append(i+1)if number not in check_numls:tk.messagebox.showinfo(title='提示', message='请输入正确的爬取数量(1--60)')returnif keyword == '':tk.messagebox.showinfo(title='提示', message='请输入关键词')returngoodslist = GoodsList(keyword,number,tmall=tm,jd=jd,pdd=pdd)goodslist.getGoods()if self.sort_var.get() == 1:self.goodsinfo.extend(goodslist.getGoodsList())elif self.sort_var.get() == 2:self.goodsinfo.extend(goodslist.sort())else:self.goodsinfo.extend(goodslist.sort(reverse = True))self.showdata()tk.messagebox.showinfo(title='提示', message='爬取完成/n*拼多多商品销量为总销量 , 天猫销量为月销量')#显示信息def showdata(self):for item in self.tree.get_children():self.tree.delete(item)if not self.goodsinfo:tk.messagebox.showinfo(title = '提示',message = '当前无商品信息')returnelse:num = 1for goods in self.goodsinfo:goodslist = [num,goods.getID(),goods.getPlatform(),goods.getTitle(),goods.getShop(),goods.getPrice(),goods.getSales(),goods.getHref()]self.tree.insert('','end',values = goodslist)num = num+1#比价def compare(self):num_ls = self.num_var.get().split(' ')num_ls = list(set(num_ls))compare_ls = []for num in num_ls:if num == '':continuetry:if not isinstance(eval(num), int):tk.messagebox.showinfo(title='提示', message='请输入正确的序号')returnelif eval(num)> len(self.goodsinfo) or eval(num) < 1:tk.messagebox.showinfo(title='提示', message='请输入正确的序号')returnelse:compare_ls.append(self.goodsinfo[eval(num)-1])except:tk.messagebox.showinfo(title='提示', message='请输入正确的序号')returngoodslist = GoodsList('', 0)result = goodslist.compare(compare_ls)tk.messagebox.showinfo(title='比价结果', message=result)#加入关注列表def addtoDB(self):num_ls = self.num_var.get().split(' ')num_ls = list(set(num_ls))add_ls = []for num in num_ls:if num == '':continuetry:if not isinstance(eval(num), int):tk.messagebox.showinfo(title='提示', message='请输入正确的序号')returnelif eval(num) > len(self.goodsinfo) or eval(num)
- python 四维数据怎么看性别_四维单子数据看男女
- python 百度云文字识别 proxy_Python基于百度AI的文字识别的示
- python 四维数据怎么看性别_四维彩超怎么看性别?四维看男孩女孩诀窍
- Python对商品属性进行二次分类并输出多层嵌套字典
- Graph Neural Network——图神经网络
- 带附属txt文件 将python文件打包成exe文件
- 聊聊“文章代写”这个传统网络项目
- 角色手游排行榜2020前十名,大型网络游戏排行榜2011前十名
- 什么游戏一天赚1000块,玩网络游戏一天可以赚到10元吗?
- macOS自带网络测速功能使用教程