時間:2023-06-22 07:00:02 | 來源:網(wǎng)站運營
時間:2023-06-22 07:00:02 來源:網(wǎng)站運營
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()
當然這個界面中什么都沒有,接下來就是對這個界面進行修改,比如先調(diào)整大小和背景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)
最后再添加億點細節(jié)就差不多了!關(guān)鍵詞:使用
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。