本文實(shí)例為大家分享了python個(gè)性簽名設(shè)計(jì)的具體代碼,供大家參考,具體內(nèi)容如下
參考博客:Python GUI Tkinter簡(jiǎn)單實(shí)現(xiàn)個(gè)性簽名設(shè)計(jì)
參考博客:python3爬蟲之設(shè)計(jì)簽名小程序
Code
from tkinter import *from tkinter import messageboximport requestsimport refrom PIL import Image,ImageTk#模擬瀏覽器發(fā)送請(qǐng)求def download(): startUrl = 'http://www.uustv.com/' name = enter.get() #name = name.strip() if not name: messagebox.showinfo('提示:','請(qǐng)輸入用戶名') else: data= { 'word':name, 'sizes':60, 'fonts':'jfcs.ttf', 'fontcolor':'#000000' } result = requests.post(startUrl,data = data) result.encoding = 'utf-8' html = result.text reg ='<div class="tu">.*?<img src="(.*?)"/></div>' imagePath = re.findall(reg,html) #圖片完整路徑 imgUrl = startUrl + imagePath[0] #獲取圖片內(nèi)容 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) #image屬性 label2.bm = bm #繪圖 label2.grid(row = 2,columnspan = 2)#創(chuàng)建窗口root = Tk()#標(biāo)題root.title('簽名設(shè)計(jì)')#窗口大小,中間的是小寫的x,而不 是乘號(hào)root.geometry('600x300')#窗口的初始位置root.geometry('+400+300')#標(biāo)簽的控件label = Label(root,text = '簽名',font = ('華文行楷',20),fg = 'red')#grid pack placelabel.grid()#輸入框enter = Entry(root,font = ('微軟雅黑',20))#設(shè)置輸入框的位置enter.grid(row = 0,column = 1)#點(diǎn)擊按鈕button = Button(root,text = '設(shè)計(jì)簽名',font =('微軟雅黑',20),command = download) #調(diào)用函數(shù)#設(shè)置點(diǎn)擊按鈕的位置button.grid(row = 1,column = 0)#消息循環(huán),可以理解為顯示窗口root.mainloop()
Results
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林站長站。
新聞熱點(diǎn)
疑難解答
圖片精選