Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python Library Learning Tkinter how to make GUI Personality signature Design Software

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Python library learns how to make GUI personalized signature design software by Tkinter. In view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Introduction to Tkinter

Since Tkinter is the standard library that comes with Python, when we want to use it, we just need to import it directly.

From tkinter import *

The components supported by Tkinter are:

Tkinter can still handle a simple graphical interface, but the interface made by PyQt5 is not beautiful enough, and the code is too cumbersome compared to Pysimplegui. These two libraries are buried in a hole, and a separate introduction will be opened later.

The overall idea today is: first select an online signature website, find the interface to simulate the request, then download the generated signature image to the local, and finally display it on the GUI window generated by Tkinter.

Get individual signature map

Before making personalized signature software, the first thing is to find a suitable website and get their interface.

Why do you want to find the right website?

A search engine search "signature design", it is really gaudy ah, my aesthetic impact. "random flowers" to find a circle, just picked a slightly more normal website.

Website address: http://www.yishuzi.com/b/13.htm

F12 developer mode, select Network. Manually adjust the color matching to # 000000 black, adjust the background to # FFFFFF white, enter a name casually and click generate.

It is very easy to find the request that the website generates a signature to send. As follows:

Don't talk too much nonsense, just go to Python!

Request the URL through requests.post () and import the parameters.

There are two most important parameters: id corresponds to the generated name, and id1 corresponds to the artistic font.

Import requestsfrom urllib.request import urlretrieveurl = 'http://www.yishuzi.com/b/re13.php'd = requests.post (url, data= {' id': 'test signature', 'zhenbi':' 20191123 signature, 'id1':' 904 signature, 'id2':' # FFFFFF', 'id4':' # 00000' 'id6':' # 000000'}) d.content.decode ("utf-8")

As you can see, post () returns a string with a link.

It is easy to extract the growing personality signature image from the returned string. Then download the image locally with urlretrieve (), and finally package it as a custom function.

Def create_sign (word): url = 'http://www.yishuzi.com/b/re13.php' d = requests.post (url, data= {' id': word, 'zhenbi':' 20191123, 'id1':' 904, 'id2':' # FFFFFF', 'id4':' # 00000' 'id6':' # 000000'}) myurl = d.content.decode ("utf-8"). Split ('") [1] urlretrieve (myurl, word + '.png')

Later in the design of the software GUI interface, directly call this function, you can directly generate a personality signature.

Design software GUI interface

The download signature image function create_sign () has been created, and the work is actually half done.

The rest is for us to design the software interface, so we might as well draw a simple sketch first.

Here we mainly use: Label (label control), Entry (input control), Button (button control), Frame (frame control) and Combobox (drop-down list box) when selecting fonts.

The previous controls have been introduced, specifically look at this 8000 words, Tkinter detailed use of the tutorial! Here I just focus on the drop-down list box.

Drop-down list box

Python forms (Tkinter) drop-down list box Combobox. It is a part of the ttk module under the Tkinter module, and the effect is a drop-down list box, which is a widget in the GUI. When the user clicks on the drop-down list to get the value, it is selected from the list, and a virtual event named is generated.

Several common parameters are:

Syntax functions cv = tk.stringVar () binding variable com = ttk.Combobox (root, textvariable=cv) create drop-down box com.pack () place drop-down box com ["value"] = ('text', text') set drop-down data com.current (index) set default value demo = com.get () variable accept value com.bind (", function name) drop-down data click to call the function

Simply use a small example to help you understand.

Import tkinterfrom tkinter import ttkroot = tkinter.Tk () root.geometry ("400x200") xVariable = tkinter.StringVar () # create variable com = ttk.Combobox (root, textvariable=xVariable) # create drop-down menu com.pack () # bind drop-down menu to form com ["value"] = ("option 1", "option 2", "option 3", "option 4") com.current (0) # set the default value for the drop-down menu root.mainloop ()

After running, the effect is as follows.

So we can get the last selected value in the drop-down box through com.get ().

Design interface

The rest of the interface design is much simpler, just arrange Label (label control), Entry (input control), Button (button control), Frame (frame control), and Combobox (drop-down list box).

Think back to the previous sketch, open it up!

Specify the window size as 600x400, and then set the basic properties of the window.

All the components use place geometry method to plan the size and layout of the components reasonably. At the same time, Button components are also linked with their corresponding function create_sign (word).

Some of the code is shown below, and the complete code is shown at the end of the article.

Root = Tk () root.title ("signature design by: quick learning Python") root.geometry ("600x400") bg_image = PhotoImage (file = 'background.png') bg_label = Label (root, image = bg_image) bg_label.place (relwidth = 1, relheight = 1) frame = Frame (root, bg =' # edcc79', bd = 5) frame.place (relx = 0.5,0.1,0.1,0.75, relheight = 0.1 jigsaw ='n') font_label = Label (frame) Text = 'input signature:', font = ('Microsoft Yahei', 16), fg = 'black') font_label.place (relwidth = 0.25, relheight = 1) name_entry = Entry (frame, font = (' Microsoft Yahei', 16))

The final product, show it.

Enter the name, click generate, and do it in one go! Different styles, one-click conversion!

In this way, we have completed another small case of Tkinter actual combat.

This is the answer to the question about Python library learning Tkinter how to make GUI personalized signature design software. I hope the above content can be of some help to everyone. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report