前话:IP
import requests
import tkinter as tk
def on_button_click():
targetUrl = "http://bapi.51daili.com/getapi2?linePoolIndex=-1&packid=2&unkey=&tid=&qty=1&time=5&port=1&format=txt&ss=1&css=®ionCode=0&pro=&city=&dt=0&isp=0&ct=0&service=1&usertype=17&accessName=18935125480"
resp = requests.get(targetUrl, verify=False)
print (resp.status_code)
print (resp.text)
label1.config(text=resp.text )
def copy():
content = label1.cget("text")
# 复制到剪贴板
root.clipboard_clear()
root.clipboard_append(content)
root.update()
# 创建主窗口
root = tk.Tk()
root.geometry('300x200')
root.title("动态获取IP代理")
# 创建标签
label1 = tk.Label(root, text="点击按钮获取IP")
label1.pack(pady=10)
# 创建按钮
button = tk.Button(root, text="点击获取", command=on_button_click)
button.pack(pady=10)
# 创建按钮2
button1 = tk.Button(root, text="复制", command=copy)
button1.pack(pady=10)
# 开始主循环
root.mainloop()