最终效果
代码
import tkinter as tk
from tkinter import messagebox
import requests
import re
import time
window = tk.Tk()
window.title('签名设计')
window.geometry('520x400')
window.resizable(0,0)
canvas = tk.Canvas(window,height=200,width=500)
e = tk.Entry(window,show=None,font=('楷体',20))
e.place(x=100,y=0)
label = tk.Label(window,text='姓名',font=('楷体',20))
label.place(x=30,y=0)
def download():
start_url = 'http://www.uustv.com/'
name = e.get()
name=name.strip()
if name=='':
messagebox.showinfo('提示','请输入名字')
else:
data = {
'word': name,
'sizes': 60,
'fonts': 'jfcs.ttf',
'fontcolor': '#000000'
}
result = requests.post(start_url,data=data)
result.encoding = 'utf-8'
html = result.text
reg = '<div class="tu">.*?<img src="(.*?)"/>.*?</div>'
img_path = re.findall(reg,html)
img_url = start_url + img_path[0]
response = requests.get(img_url).content
f = open('1.gif','wb')
f.write(response)
show()
b = tk.Button(window,text='签名设计',bg='orange',font=('楷体',20),command=download,width=10,height=2)
b.place(x=180,y=30)
def show():
image_file=tk.PhotoImage(file='1.gif')
canvas.create_image(0,0,anchor='nw',image=image_file)
canvas.pack(side='left')
window.update()
time.sleep(3)
window.mainloop()
显示图片
import tkinter as tk
wd=tk.Tk()
wd.geometry('600x400')
img = tk.PhotoImage(file = '1.gif')
label = tk.Label(wd, image=img)
label.pack()
tk.mainloop()