python 制作手機(jī)歸屬地查詢工具(附源碼)
Hello,大家好,我來(lái)敷衍你們了 [捂臉],今天還是用Tkinter做一個(gè)GUI小工具,用于手機(jī)歸屬地查詢。我將代碼放在了博文中,程序打包好放在藍(lán)奏云。
一.預(yù)覽
1.啟動(dòng)
2.執(zhí)行查詢
二.源代碼
1.GUI
from tkinter import * from tkinter import ttk from tkinter import messagebox from Get_Attr import Get_Infos import re import threading class App: def __init__(self): self.root=Tk() self.root.title('手機(jī)號(hào)碼歸屬地查詢-v1.0') self.root.resizable(0,0) width=410 height=390 left=(self.root.winfo_screenwidth()-width)/2 top=(self.root.winfo_screenheight()-height)/2 self.root.geometry('%dx%d+%d+%d'%(width,height,left,top)) self.create_widet() self.set_widget() self.place_widget() self.root.mainloop() def create_widet(self): self.l1=ttk.Label(self.root) self.e1=ttk.Entry(self.root) self.b1=ttk.Button(self.root) self.lf=ttk.LabelFrame(self.root) self.l2=ttk.Label(self.lf) self.e2=ttk.Entry(self.lf) self.l3=ttk.Label(self.lf) self.e3=ttk.Entry(self.lf) self.l4=ttk.Label(self.lf) self.e4=ttk.Entry(self.lf) self.l5=ttk.Label(self.lf) self.e5=ttk.Entry(self.lf) self.l6=ttk.Label(self.lf) self.e6=ttk.Entry(self.lf) self.l7=ttk.Label(self.lf) self.e7=ttk.Entry(self.lf) self.b1.config(command=lambda:self.thread_it(self.search_infos)) def set_widget(self): self.e2_var=StringVar() self.e3_var=StringVar() self.e4_var=StringVar() self.e5_var=StringVar() self.e6_var=StringVar() self.e7_var=StringVar() self.l1.config(text='請(qǐng)輸入手機(jī)號(hào):') self.b1.config(text='查詢') self.lf.config(text='查詢結(jié)果') self.l2.config(text='手機(jī)號(hào)碼:') self.l3.config(text='所屬省份:') self.l4.config(text='所屬城市:') self.l5.config(text='區(qū) 號(hào):') self.l6.config(text='郵 編:') self.l7.config(text='類 型:') #將字符串變量綁定Entry組件 self.e2.config(textvariable=self.e2_var) self.e3.config(textvariable=self.e3_var) self.e4.config(textvariable=self.e4_var) self.e5.config(textvariable=self.e5_var) self.e6.config(textvariable=self.e6_var) self.e7.config(textvariable=self.e7_var) self.root.bind('<Escape>',self.escape) self.root.bind('<Return>',self.do_search) def place_widget(self): self.l1.place(x=30,y=20) self.e1.place(x=130,y=20) self.b1.place(x=290,y=20) self.lf.place(x=30,y=60,width=350,height=300) self.l2.place(x=60,y=10) self.e2.place(x=150,y=10) self.l3.place(x=60,y=50) self.e3.place(x=150,y=50) self.l4.place(x=60,y=90) self.e4.place(x=150,y=90) self.l5.place(x=60,y=130) self.e5.place(x=150,y=130) self.l6.place(x=60,y=170) self.e6.place(x=150,y=170) self.l7.place(x=60,y=210) self.e7.place(x=150,y=210) def search_infos(self): pn=self.e1.get() #判斷輸入類型,必須為11位數(shù)字 if re.match('\d{11}',pn): result=Get_Infos().get_infos(pn) self.e2_var.set(pn) self.e3_var.set(result['province']) self.e4_var.set(result['city']) self.e5_var.set(result['areacode']) self.e6_var.set(result['zip']) self.e7_var.set(result['company']) else: messagebox.showwarning('警告','輸入有誤,請(qǐng)檢查!') #使用線程防止UI界面卡死 def thread_it(self,func,*args): t=threading.Thread(target=func,args=args) t.setDaemon(True) t.start() def escape(self,event): self.root.destroy() def do_search(self,event): self.thread_it(self.search_infos()) if __name__ == '__main__': a=App()
2.Get_Attr
import json import requests from urllib.parse import urlencode class Get_Infos(): def __init__(self): self.url='http://apis.juhe.cn/mobile/get?' self.headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36' } def get_infos(self,phone_num): params={ 'phone':phone_num, 'key':'7a2b367a62fa24108b1f27ed4c84c97a', 'dtype':'' } r=requests.get(self.url+urlencode(params),headers=self.headers) _json=json.loads(r.text) if _json.get('resultcode')=='200': result=_json.get('result') item={} item['province']=result.get('province') item['city']=result.get('city') item['areacode']=result.get('areacode') item['zip']=result.get('zip') item['company']=result.get('company') return item else: return False
三.總結(jié)
本次使用Tkinter制作了一款手機(jī)歸屬地查詢小工具,簡(jiǎn)單調(diào)用了一個(gè)接口,基本上沒(méi)有什么難度,就是為了水一篇博客[狗頭],程序打包好了放在了這里思路、代碼方面有什么不足歡迎各位大佬指正、批評(píng)!
以上就是python 制作手機(jī)歸屬地查詢工具(附源碼)的詳細(xì)內(nèi)容,更多關(guān)于python 手機(jī)歸屬地查詢的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
完美解決python針對(duì)hdfs上傳和下載的問(wèn)題
這篇文章主要介紹了完美解決python針對(duì)hdfs上傳和下載的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06Python中subprocess模塊用法實(shí)例詳解
這篇文章主要介紹了Python中subprocess模塊用法,實(shí)例分析了subprocess模塊的相關(guān)使用技巧,需要的朋友可以參考下2015-05-05Python中的def __init__( )函數(shù)
這篇文章主要介紹了Python中的def __init__( )函數(shù),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-09-09Python多線程操作之互斥鎖、遞歸鎖、信號(hào)量、事件實(shí)例詳解
這篇文章主要介紹了Python多線程操作之互斥鎖、遞歸鎖、信號(hào)量、事件,結(jié)合實(shí)例形式詳細(xì)分析了Python多線程操作互斥鎖、遞歸鎖、信號(hào)量、事件相關(guān)概念、原理、用法與操作注意事項(xiàng),需要的朋友可以參考下2020-03-03Python面向?qū)ο蟮娜筇匦苑庋b、繼承、多態(tài)
這篇文章介紹了Python面向?qū)ο蟮娜筇匦苑庋b、繼承、多態(tài),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07python簡(jiǎn)易實(shí)現(xiàn)任意位數(shù)的水仙花實(shí)例
今天小編就為大家分享一篇python簡(jiǎn)易實(shí)現(xiàn)任意位數(shù)的水仙花實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-11-11Python利用帶權(quán)重隨機(jī)數(shù)解決抽獎(jiǎng)和游戲爆裝備問(wèn)題
帶權(quán)重隨機(jī)數(shù)即是隨機(jī)數(shù)各個(gè)區(qū)間段被抽中的概率根據(jù)權(quán)重而不同,這里我們就來(lái)看一下Python利用帶權(quán)重隨機(jī)數(shù)解決抽獎(jiǎng)和游戲爆裝備問(wèn)題的方法,首先還是來(lái)進(jìn)一步解釋帶權(quán)隨機(jī)數(shù):2016-06-06python實(shí)現(xiàn)基于SVM手寫(xiě)數(shù)字識(shí)別功能
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)基于SVM手寫(xiě)數(shù)字識(shí)別功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01