制作签名小案例
效果圖:
網(wǎng)站:http://www.uustv.com/
思路
先設(shè)計窗口,在通過爬蟲得到圖片,保存并放在窗口中,此爬蟲完全沒有加密
from tkinter import * from tkinter import messagebox from PIL import Image,ImageTk import requests import re#模擬瀏覽器發(fā)送請求 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'#獲取網(wǎng)站的源代碼html =result.textreg = '<div class="tu">.<img src="(.*?)"/></div>'#正則表達 (.*?)全部都需要匹配imagePath = re.findall(reg,html)#獲取圖片的完整路徑imgUrl = startUrl + imagePath[0]print(imgUrl)#獲取圖片內(nèi)容response = requests.get(imgUrl).contentf = open('{}.gif'.format(name),'wb')f.write(response)#圖片顯示到窗口上bm = ImageTk.PhotoImage(file ='{}.gif'.format(name))label2= Label(root,image = bm)label2.bm = bmlabel2.grid(row = 2,columnspan= 2) #創(chuàng)建窗口 root = Tk() #標(biāo)題 root.title('毛利專用簽名') #窗口大小 寬 高 root.geometry('600x300') #窗口初始位置 root.geometry('-500+200') #標(biāo)簽控件 label = Label(root,text = '簽名',font = ('華文行楷',20),fg = 'blue') label.grid(row =0,column=0)#設(shè)計輸入框 entry = Entry(root,font=('微軟雅黑',20)) entry.grid(row =0,column=1) #點擊按鈕 button = Button(root,text = '設(shè)計簽名',font=('微軟雅黑',22),command =download) button.grid(row =1,column=0) #消息循環(huán) 顯示窗口 root.mainloop()總結(jié)
- 上一篇: 二十九、深入Python中的collec
- 下一篇: 想在农村开个电商怎么做 想创业的投资不要