python 制作手机归属地查询工具(附源码)

作者:懷淰メ 时间:2023-07-05 07:02:34 

目录
  • 一.预览

    • 1.启动

    • 2.执行查询

  • 二.源代码

    • 1.GUI

    • 2.Get_Attr

  • 三.总结

    Hello,大家好,我来敷衍你们了 [捂脸],今天还是用Tkinter做一个GUI小工具,用于手机归属地查询。我将代码放在了博文中,程序打包好放在蓝奏云。

    一.预览

    1.启动

    python 制作手机归属地查询工具(附源码)

    2.执行查询

    python 制作手机归属地查询工具(附源码)

    二.源代码

    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('手机号码归属地查询-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='请输入手机号:')
       self.b1.config(text='查询')
       self.lf.config(text='查询结果')
       self.l2.config(text='手机号码:')
       self.l3.config(text='所属省份:')
       self.l4.config(text='所属城市:')
       self.l5.config(text='区   号:')
       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位数字
       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('警告','输入有误,请检查!')

    #使用线程防止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

    三.总结

    本次使用Tkinter制作了一款手机归属地查询小工具,简单调用了一个接口,基本上没有什么难度,就是为了水一篇博客[狗头],程序打包好了放在了这里思路、代码方面有什么不足欢迎各位大佬指正、批评!

    来源:https://blog.csdn.net/a1397852386/article/details/114417218

    标签:python,手机,归属地,查询
    0
    投稿

    猜你喜欢

  • SQL SERVER的优化建议与方法

    2024-01-20 15:14:58
  • Python PaddleGAN实现调整照片人物年龄

    2023-09-28 05:48:14
  • pytorch 实现在预训练模型的 input上增减通道

    2023-12-02 00:49:33
  • vue-swiper的使用教程

    2024-04-27 16:17:56
  • Python中pygame的mouse鼠标事件用法实例

    2021-02-09 12:21:41
  • Python生产者与消费者模型中的优势介绍

    2023-06-18 01:21:17
  • python3检查字典传入函数键是否齐全的实例

    2023-11-07 07:36:31
  • Python Matplotlib简易教程(小白教程)

    2023-12-29 05:31:57
  • python dataframe向下向上填充,fillna和ffill的方法

    2021-11-07 18:16:47
  • Python中isnumeric()方法的使用简介

    2023-05-23 19:25:23
  • Python实现简单2048小游戏

    2023-08-13 00:19:18
  • 制定设计的原则

    2011-01-10 20:43:00
  • pyhon如何把程序打包为whl

    2023-06-16 11:30:48
  • Pytorch中实现只导入部分模型参数的方式

    2023-01-24 05:53:25
  • vue element-ul实现展开和收起功能的实例代码

    2024-05-29 22:48:16
  • MySQL 5.5主从同步设置笔记分享

    2024-01-27 10:12:29
  • python 使用xlsxwriter循环向excel中插入数据和图片的操作

    2023-01-30 15:08:47
  • windows系统mysql压缩包版本安装过程

    2024-01-14 16:47:38
  • Go位集合相关操作bitset库安装使用

    2024-05-09 14:57:22
  • oracle-快速删除重复的记录

    2008-01-16 19:12:00
  • asp之家 网络编程 m.aspxhome.com