本帖最后由 星河尽明意LH 于 2020-5-14 10:50 编辑
这个软件是基于python的requests模块写的,主要原理是通过一个第三方网站生成二维码然后下载到本地
初学python,有写的不好的地方请大家多多指教!
链接: https://pan.baidu.com/s/1SlUoZeX0iFJRjdn07VnC-A 提取码: 3ft9
[Python] 纯文本查看 复制代码 import requests
import tkinter as tk
import tkinter.messagebox
#生成一个窗口
window = tk.Tk()
window.title('LH二维码生成器')
window.geometry('300x200')
#生成标签
l_content=tk.Label(window,text='请输入文本:',
font=('Arial',12),width=15,height=2)
l_content.pack()
#生成输入框
e_content = tk.Entry(window)
e_content.pack()
#生成标签
l_size=tk.Label(window,text='请输入尺寸(1-10):',
font=('Arial',12),width=20,height=2)
l_size.pack()
#生成输入框
e_size = tk.Entry(window)
e_size.pack()
#定义headers
headers = {"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400"}
content = ''
size=''
#定义data
data = {}
data['error']='3'
data['size']=size
data['txtarea']=content
#定义访问的网址
post_url = "http://tool.chinaz.com/qrcode"
#生成图片链接的函数
def check_jpg_url(post_url,data,headers):
response = requests.post(post_url,data=data,headers=headers)
response = response.content.decode('utf-8')
a = response.find('img src=\'/template/')
b = response.find('.jpg',a,a+255)
url_str = response[a+9:b+4]
jpg_url = 'http://tool.chinaz.com/' + url_str
return jpg_url
#保存图片的函数
def save_jpg(jpg_url):
jpg_name = '二维码.jpg'
with open(jpg_name,'wb') as f:
img = requests.get(jpg_url)
f.write(img.content)
#设置二维码内容的函数
def set_content(data):
content = e_content.get()
data['txtarea']=content
#设置二维码尺寸的函数
def set_size(data):
size = e_size.get()
data['size']=size
#主函数
def main():
set_content(data)
set_size(data)
jpg_url = check_jpg_url(post_url,data,headers)
save_jpg(jpg_url)
tkinter.messagebox.showinfo('提示','生成成功!')
#创建‘生成’按钮
b = tk.Button(window,text='生成',width=15,height=2,
command=main)
b.pack()
window.mainloop()
|