Py学习  »  Python

Python帮你设计个人签名

python • 5 年前 • 595 次点击  

前言

只要你离开了学校,基本上写字的机会就变得很少了,但是签名的机会却很多,如果写字不好好看的话,但是能签的一手好的名字,也是很不错的选择。


基础环境配置

版本:Python3.6

模块:tkinter、PIL、requests

tkinter是内置模块不需要安装

PIL:pip install pillow

requests:pip install requests

//
实现效果图
//



//
GUI用户使用界面
//


from tkinter import *
from tkinter import messagebox
#创建窗口
root = Tk()
#标题
root.title('Python学习群:516107834')
#窗口大小     宽 高
root.geometry('600x300')
#窗口初始位置
root.geometry('-500+200')
#标签控件
label = Label(root,text = '签名',font = ('华文行楷',20),fg = 'blue')
label.grid(row =0,column=0)

#设计输入框
entry = Entry(root,font=('微软雅黑',20))
entry.grid(row =0,column=1)
#点击按钮
button = Button(root,text = '设计签名',font=('微软雅黑',22)
                ,command =download)
button.grid(row =1,column=0)
#消息循环  显示窗口
root.mainloop()


//
爬取设计签名网站数据
//


import requests
import re

#模拟浏览器发送请求
def download():

    startUrl ='http://www.uustv.com/'
    #获取用户输入的姓名
    name = entry.get()
    #去空格
    name = name.strip()
    if name =='':
        messagebox.showinfo('提示:','请输入用户名')
    else:
        date = {
            'word':name,
            'sizes':'60',
            'fonts':'jfcs.ttf',
            'fontcolor':'#000000'
        }
        result = requests.post(startUrl,data=date)
        result.encoding = 'utf-8'
        #获取网站的源代码
        html =result.text
        reg = '
.
'

        #正则表达  (.*?)全部都需要匹配
        imagePath = re.findall(reg,html)
        #获取图片的完整路径
        imgUrl = startUrl + imagePath[0]
        print(imgUrl)
         #获取图片内容
        response = requests.get(imgUrl).content
        f = open('{}.gif'.format(name),'wb')
        f.write(response)

        #图片显示到窗口上
        bm = ImageTk.PhotoImage(file ='{}.gif'.format(name))

        label2= Label(root,image = bm)
        label2.bm = bm
        label2.grid(row = 2,columnspan= 2)


//
完整代码
//


from tkinter import *
from tkinter import messagebox
from PIL import  Image,ImageTk
import requests
import re

#模拟浏览器发送请求
def download():

    startUrl ='http://www.uustv.com/'
    #获取用户输入的姓名
    name = entry.get()
    #去空格
    name = name.strip()
    if name =='':
        messagebox.showinfo('提示:','请输入用户名')
    else:
        date = {
            'word':name,
            'sizes':'60',
            'fonts':'jfcs.ttf',
            'fontcolor':'#000000'
        }
        result = requests.post(startUrl,data=date)
        result.encoding = 'utf-8'
        #获取网站的源代码
        html =result.text
        reg = '
.
'

        #正则表达  (.*?)全部都需要匹配
        imagePath = re.findall(reg,html)
        #获取图片的完整路径
        imgUrl = startUrl + imagePath[0]
        print(imgUrl)
         #获取图片内容
        response = requests.get(imgUrl).content
        f = open('{}.gif'.format(name),'wb')
        f.write(response)

        #图片显示到窗口上
        bm = ImageTk.PhotoImage(file ='{}.gif'.format(name))

        label2= Label(root,image = bm)
        label2.bm = bm
        label2.grid(row = 2,columnspan= 2)
#创建窗口
root = Tk()
#标题
root.title('Python学习群:516107834')
#窗口大小     宽 高
root.geometry('600x300')
#窗口初始位置
root.geometry('-500+200')
#标签控件
label = Label(root,text = '签名',font = ('华文行楷',20),fg = 'blue')
label.grid(row =0,column=0)

#设计输入框
entry = Entry(root,font=('微软雅黑',20))
entry.grid(row =0,column=1)
#点击按钮
button = Button(root,text = '设计签名',font=('微软雅黑',22)
                ,command =download)
button.grid(row =1,column=0)
#消息循环  显示窗口
root.mainloop()


公众号推荐




今天看啥 - 高品质阅读平台
本文地址:http://www.jintiankansha.me/t/Nep95m3cmp
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/26963
 
595 次点击