签名小程序

from tkinter import *
from tkinter import messagebox
import requests
import re
from urllib.request import urlretrieve
from PIL import ImageTk
from tkinter import ttk


def download():
    path = './签名图.gif'
    Url2 = 'http://m.uustv.com/'
    name = entry.get()
    name = name.strip()
    fonts1 = choice.get()
    if name == '':
        messagebox.showinfo('提示:','请输入有效名字')
    else:
        if fonts1 == '个性签':
            fonts1='jfcs.ttf'
        elif fonts1 == '连笔签':
            fonts1='qmt.ttf'
        elif fonts1 == '潇洒签':
            fonts1='bzcs.ttf'
        elif fonts1 == '草体签':
            fonts1='lfc.ttf'
        elif fonts1 == '合文签':
            fonts1='haku.ttf'
        elif fonts1 == '商务签':
            fonts1='zql.ttf'
        else :
            fontsl='yqk.ttf'

    #爬取代码是借鉴别人的  
        data1 = {
            'word':name,
            'sizes':'60',
            'fonts':fonts1,
            'fontcolor':'#000000'
            }
        req = requests.post(Url2, data=data1)
        req.encoding = req.apparent_encoding
        reg = re.compile('<div class="tu"><img src="(.*?)"/></div>')
        res = re.findall(reg,req.text)
        res = Url2 + res[0]
        urlretrieve(res,path)
        bm = ImageTk.PhotoImage(file = path)
        L1 = Label(root,image = bm)
        L1.bm = bm
        L1.grid(row = 2,columnspan = 3)

# 以下代码是大家设计的
root = Tk()

root.title("生成签名小软件")

root.geometry("600x310+400+150")

label = Label(root,text = "请输入签名",font = ("华文行楷",20),fg="blue")

label.grid()

entry = Entry(root,font = ('微软雅黑',20))

entry.grid(row = 0,column = 1)

button1 = Button(root,text = '点击设计签名',font = ('微软雅黑',20),command = download)

button1.grid(row=1,column=1)

choice = ttk.Combobox(root,width = 6)

choice.grid(row = 0,column = 3)

choice['values'] = ('个性签','连笔签','潇洒签','草体签','合文签'
                    ,'商务签','可爱签')
choice.current(0)

root.mainloop()

 

上一篇:matplotlib常见问题


下一篇:freeType2.9.1移植到A7(2)