时间:2023-06-22 07:00:02 | 来源:网站运营
时间:2023-06-22 07:00:02 来源:网站运营
PythonGUI编程|使用Tkinter制作快递查询软件:import requestsimport bs4import rekuaidi = []url='http://m.46644.com/express/result.php?typetxt=%D6%D0%CD%A8&type=zto&number=你的单号'response = requests.get(url)response.encoding = 'gb18030' response = response.textsoup = bs4.BeautifulSoup(response,'html.parser',from_encoding="utf8")for i in soup.findAll(name='div',attrs = {'class':'icontent'}): kuaidi.append(i.get_text()) print(i.get_text())
这一段代码我们使用多很多次就不过多解读了,用Requests请求并使用bs4提取我们需要的信息,当然注意到这只是中通快递的查询链接import tkinter as tkroot = tk.Tk()root.mainloop()
当然这个界面中什么都没有,接下来就是对这个界面进行修改,比如先调整大小和背景import tkinter as tkHEIGHT = 500WIDTH = 600root = tk.Tk()canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)canvas.pack()background_image = tk.PhotoImage(file='/Users/liuhuanshuo/Desktop/bg1.png')background_label = tk.Label(root, image=background_image)background_label.place(relwidth=1, relheight=1)root.mainloop()
接着我们用下面的代码添加按钮和输入框frame = tk.Frame(root, bg='#80c1ff', bd=5)frame.place(relx=0.5, rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')entry = tk.Entry(frame, font=40)entry.place(relwidth=0.65, relheight=1)button = tk.Button(frame, text="查快递", font=40, command=lambda: kuaidi(entry.get()))button.place(relx=0.7, relheight=1, relwidth=0.3)
最后再添加亿点细节就差不多了!关键词:使用