利用ChatGPT开发一个Python的桌面应用程序ip查询
利用ChatGPT开发一个Python的桌面应用小工具
1、源码分享
import tkinter as tk
from tkinter import ttk
import requests
def get_ip_location(ip):
url = "http://ip-api.com/json/{}?lang=zh-CN".format(ip)
response = requests.get(url)
data = response.json()
if data["status"] == "success":
return "IP地址:{}\n归属地:{} {} {}".format(data['query'], data['country'], data['regionName'], data['city'])
else:
return "查询失败"
def get_public_ip_location():
url = "http://ip-api.com/json/?lang=zh-CN"
response = requests.get(url)
data = response.json()
if data["status"] == "success":
return "IP地址:{}\n归属地:{} {} {}".format(data['query'], data['country'], data['regionName'], data['city'])
else:
return "查询失败"
def search_ip_location():
ip = ip_entry.get()
result = get_ip_location(ip)
result_label.config(text=result)
def show_public_ip_location():
result = get_public_ip_location()
result_label.config(text=result)
# 创建窗口
window = tk.Tk()
window.title("IP地址查询 MaskTT博客 www.masktt.com")
window.geometry("420x250")
# 设置窗口不可调整大小
window.resizable(False, False)
# 设置窗口图标
#window.iconbitmap("logo.ico")
# 创建样式
style = ttk.Style()
style.configure("TButton", font=("Helvetica", 12), padding=10)
style.configure("TLabel", font=("Helvetica", 12), padding=10)
style.configure("TEntry", font=("Helvetica", 12), padding=10)
# 创建组件
ip_label = ttk.Label(window, text="输入IP地址:")
ip_label.pack()
ip_entry = ttk.Entry(window, font=("Helvetica", 12), width=25)
ip_entry.pack()
search_button = ttk.Button(window, text="查询", command=search_ip_location, padding=(10, 5))
search_button.pack()
result_label = ttk.Label(window, text="", wraplength=400)
result_label.pack()
# 显示当前公网IP地址归属地
result = get_public_ip_location()
result_label.config(text=result)
# 运行窗口
window.mainloop()
2、程序下载
下载链接:https://pan.baidu.com/s/1BTajsEn4oaQlhebAS5A4Wg?pwd=y0m0
提取码:y0m0
文章版权声明:除非注明,否则均为MaskTT博客原创文章,转载或复制请以超链接形式并注明出处。
还没有评论,来说两句吧...