In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you how to use Python+Tkinter to create online personality signature tool related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
Idea: first select an online signature website, find the interface to simulate the request, then display the generated signature image on the GUI window generated by Tkinter, and finally save the generated signature picture
Select the URL: http://www.uustv.com/
First understand the basic steps of a crawler:
Initiate a request: send a Request, which may contain additional information such as headers,data
Get the response content: get the HTML file content of the web page
Parsing content: you can use regular expressions to extract what you want
Save data: save the data as text, or files such as mp3,mp4, or save to a database, etc.
First, determine the GUI interface:
For example:
Code:
Root = Tk () root.title ('signature tool') root.resizable (0) option='1. Art signature II. Sign 3 with a pen. Business signature 4. Regular script 5, chic signature 6. Cursive sign 7. Line bookmark 8. Personality signature 9. Lovely signature 'var1=StringVar (value='') var2=StringVar (value='') lable1=Label (root,text=option,font= (' boldface', 6)) lable2=Label (root,text=' enter your name:', font= ('boldface', 13)) entry1=Entry (root,width=40,font= ('boldface', 13), textvariable=var1) entry2=Entry (root,width=10,font= ('boldface', 13), textvariable=var2) button=Button (root,text=' OK', command=lambda:check () lable1.grid (row=0,columnspan=3) lable2.grid (row=0,column=0) entry1.grid (row=1) Column=1) entry2.grid (row=1,column=2) button.grid (row=1,column=3) root.mainloop () II. Crawl what we need
1. Crawled page style: to get the picture of the red box
two。 Parameters required to request a web page: url and form data data
Url:
Form data: as shown in the following four parameters:
Fonts is the true value of the signature style on the web page, and the style we enter
Word is the name entered
Code:
Signature = ['1.ttfjewelry url=' http://m.uustv.com/' # parameters data = {' word':name, 'sizes':60'] required parameters for requesting web pages 'fonts': feature [num-1], # 1 in the actual code means 0' fontcolor':'# 000000'} # 1. Initiate a request for a web page that needs to be crawled. Get the content of the response response=requests.post (url,data)
3. To climb a picture
# 1. Initiate a request for a web page that needs to be crawled. Get the response content response=requests.post (url,data) response.encoding='utf-8' print (response.text) # 3. Parsing content imgXpath='
'# extract the requested data imgUrls=re.findall (imgXpath,response.text) # what is regularly removed is a list content=requests.get (url+imgUrls [0]). Content # 4. Save the acquired binary content as with open ('{} .gif '.format (name),' wb') as f: f.write (content) # 5. Display the picture bg_img=ImageTk.PhotoImage (file=' {} .gif '.format (name)) # 6. Display the picture at the bottom of the GUI lable=Label (root,image=bg_img) lable.bg_img=bg_img lable.grid (row=2,columnspan=4) # on the third line, merge four columns of except: messagebox.showinfo ('prompt', message=' generation failed') pass
4. The result of crawling:
3. The complete code from tkinter import * from tkinter import messageboxfrom PIL import Image,ImageTk # pip install pillow shows the picture import reimport requestsroot = Tk () root.title ('signature tool') root.resizable (0mem0) option='1. Art signature II. Sign 3 with a pen. Business signature 4. Regular script 5, chic signature 6. Cursive sign 7. Line bookmark 8. Personality signature 9. Lovely signature 'var1=StringVar (value='') var2=StringVar (value='') def check (): # input specification processing name= entry1.get () num= entry2.get () flag= True if num.isdigit (): num= int (num) if name=='': var1.set (' cannot be empty') flag= False if name.isdigit (): var1.set ('cannot be numeric' ) flag=False if type (num) = = type ('') or num=='': var2.set ('1-9') flag=False else: if num > 9 or num
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.