效果如下:
from tkinter import * from tkinter import messagebox import requests import re from PIL import Image,ImageTk def show(root,enter): start_url = 'http://www.uustv.com/' name = enter.get() if not name: messagebox.showinfo('警告:','请输入用户名') else: data = { 'word': name, 'sizes': 60, 'fonts': 'jfcs.ttf', 'fontcolor': '#000000' } result = requests.post(start_url,data=data)#给服务器发送post 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('{}.gif'.format(name),'wb') f.write(response) bm = ImageTk.PhotoImage(file='{}.gif'.format(name)) lable2 = Label(root, image=bm) lable2.bm = bm lable2.grid(row=2,columnspan=2) def main(): root = Tk()#实例化一个对象 root.title('签名设计') root.geometry('600x300')#长600,宽300 lable = Label(root,text='签名',font=('华文行楷',20),fg='red') lable.grid(row=0,column=0) enter = Entry(root,font=('微软雅黑',22),fg='black') enter.grid(row=0,column=1) button = Button(root,text='设计签名',font=('微软雅黑',22),command=lambda :show(root,enter)) button.grid(row=1,column=0) root.mainloop() if __name__ == '__main__': main()