Python写身份证信息查询, 地区、星座、年龄、性别 等

admin 2024年3月28日01:25:44评论3 views字数 3465阅读11分33秒阅读模式
查询身份证号码用户信息查询, 地区、星座、年龄、性别 等

Python写身份证信息查询, 地区、星座、年龄、性别 等

代码:

import requestsimport tkinter as tkfrom tkinter import ttkfrom tkinter import messagebox

def get_id_card_info():    id_card = id_entry.get()    url = f"https://tools.mgtv100.com/external/v1/identity_info/query?idCard={id_card}"    response = requests.get(url)    result = response.json()

    try:        # 提取返回的数据        status = result['status']        code = str(result['code'])        data = result['data']

        # 提取个人信息        area = data['area']        province = data['province']        city = data['city']        county = data['county']        gender = data['gender']        birthday = data['birthday']        zodiac = data['zodiac']        age = data['age']        constellation = data['constellation']

        # 更新界面显示        status_label.config(text="状态:" + status)        code_label.config(text="状态码:" + code)        area_label.config(text="地区:" + area)        province_label.config(text="省份:" + province)        city_label.config(text="城市:" + city)        county_label.config(text="县区:" + county)        gender_label.config(text="性别:" + gender)        birthday_label.config(text="生日:" + birthday)        zodiac_label.config(text="生肖:" + zodiac)        age_label.config(text="年龄:" + str(age))        constellation_label.config(text="星座:" + constellation)    except KeyError:        messagebox.showerror("错误", "请输入正确的身份证号")

# 创建界面window = tk.Tk()window.title("身份证信息查询--微信公众号:蓝胖子之家")window.geometry("400x500")

# 设置背景颜色window.configure(bg="#000000")



# 创建输入框和按钮id_label = tk.Label(window, text="身份证号码:", fg="#00FF00", bg="#000000", font=("Consolas", 12))id_label.pack(pady=10)id_entry = tk.Entry(window, font=("Consolas", 12), bg="#333333", fg="#00FF00", insertbackground="#00FF00", relief="flat")id_entry.pack(pady=5)search_button = ttk.Button(window, text="查询", command=get_id_card_info, style="TButton")search_button.pack(pady=10)

search_button.pack(pady=10)

# 创建显示结果的标签status_label = tk.Label(window, text="状态:", fg="#00FF00", bg="#000000", font=("Consolas", 12))status_label.pack()code_label = tk.Label(window, text="状态码:", fg="#00FF00", bg="#000000", font=("Consolas", 12))code_label.pack()area_label = tk.Label(window, text="地区:", fg="#00FF00", bg="#000000", font=("Consolas", 12))area_label.pack()province_label = tk.Label(window, text="省份:", fg="#00FF00", bg="#000000", font=("Consolas", 12))province_label.pack()city_label = tk.Label(window, text="城市:", fg="#00FF00", bg="#000000", font=("Consolas", 12))city_label.pack()county_label = tk.Label(window, text="县区:", fg="#00FF00", bg="#000000", font=("Consolas", 12))county_label.pack()gender_label = tk.Label(window, text="性别:", fg="#00FF00", bg="#000000", font=("Consolas", 12))gender_label.pack()birthday_label = tk.Label(window, text="生日:", fg="#00FF00", bg="#000000", font=("Consolas", 12))birthday_label.pack()zodiac_label = tk.Label(window, text="生肖:", fg="#00FF00", bg="#000000", font=("Consolas", 12))zodiac_label.pack()age_label = tk.Label(window, text="年龄:", fg="#00FF00", bg="#000000", font=("Consolas", 12))age_label.pack()constellation_label = tk.Label(window, text="星座:", fg="#00FF00", bg="#000000", font=("Consolas", 12))constellation_label.pack()

# 设置按钮样式style = ttk.Style()style.configure("TButton", foreground="#00FF00", background="#000000", font=("Consolas", 12))

window.mainloop()
  1. 首先,我们导入了requests库用于发送HTTP请求,以及tkinter库用于创建GUI界面。

  2. 然后,我们定义了一个名为get_id_card_info()的函数,该函数将在用户点击“查询”按钮时被调用。该函数的作用是获取用户在输入框中输入的身份证号码,并构建了一个APIURL,该URL包含了身份证号码作为查询参数。

  3. get_id_card_info()函数中,我们使用requests库发送了一个GET请求到API,并获取到了返回的响应。我们将响应的内容解析为JSON格式,并提取出了其中的一些字段,如状态、状态码和数据。

  4. 接下来,我们更新了GUI界面上的标签,将获取到的信息显示出来。我们创建了多个标签,用于显示状态、状态码、地区、省份、城市、县区、性别、生日、生肖、年龄和星座等信息。

  5. 在主程序中,我们创建了一个tkinter的主窗口,并设置了窗口的标题和大小。

  6. 我们创建了一个标签和一个输入框,用于用户输入身份证号码,以及一个按钮用于查询信息。

  7. 我们将按钮绑定到get_id_card_info()函数,这样当用户点击按钮时,就会调用该函数进行查询。

  8. 我们还设置了按钮的样式,使其具有一定的外观效果。

  9. 最后,我们启动了tkinter的主循环,这样GUI界面就会显示出来,并且可以处理用户的交互。

运行效果:

Python写身份证信息查询, 地区、星座、年龄、性别 等

原文始发于微信公众号(蓝胖子之家):Python写身份证信息查询, 地区、星座、年龄、性别 等

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年3月28日01:25:44
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Python写身份证信息查询, 地区、星座、年龄、性别 等http://cn-sec.com/archives/2594355.html

发表评论

匿名网友 填写信息