大家好,我是九娘,今天这篇文章和大家聊聊如何用python制作个性化签名。以下是本篇文章正文内容,下面案例可供参考:
代码如下(示例):
import json import webbrowser from tkinter import * # python 3 是tkinter import tkinter.messagebox from tkinter import messagebox from urllib import parse, request import requests import re # from PIL import Image
代码如下(示例):
def download(): start_url = 'http://www.uustv.com/' name = entry.get().encode('utf-8') if not name: tkinter.messagebox.showinfo('提示', '请输入姓名再设计!') return data = { 'word': name, 'sizes': '60', 'fonts': '1.ttf', 'fontcolor': '#000000' } headers = { 'Referer': 'http://www.uustv.com/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36' } result = requests.post(start_url, data=data,headers=headers) result.encoding = 'utf-8' reg = '' img_url = start_url + re.findall(reg, result.text)[0] response = requests.get(img_url).content # 将生成的签名图片下载到本地 print(name.decode()) with open('../{}.gif'.format(name.decode()), 'wb') as f: f.write(response) try: im = Image.open('./{}.gif'.format(name.decode())) im.show() except: print('自己打开看吧') #弹窗设置 root = Tk() root.title('个性签名设计') root.geometry('+800+300') # 设置窗口出现在屏幕上面的位置 Label(root, text='姓名', font=('微软雅黑', 15)).grid() # 布局方法不要混用 entry = Entry(root, font=('微软雅黑', 15)) entry.grid(row=0, column=1) button = Button(root, text='设计签名', font=('微软雅黑', 15), width='15', height=1, command=download) button.grid(row=1, column=1) root.mainloop()
提示:这里对文章进行总结:
以上就是今天要分享的内容,本文适合初学者查阅。谢谢浏览,不要忘了点赞,收藏,关注三连哦亲!