Cow breaking! 100 lines of Python, automatically create a multi-language translation software, cool!

image

In daily study or work, it is often indispensable to read documents in foreign languages ​​or translate documents in foreign languages ​​into Chinese. At this time, you need to open the web page and search, which is very troublesome. Since it is playing Python, the editor will lead everyone to create a multi-language translation software, which can be used without any operation. Let’s take a look.

Interested students can follow the editor and send a private letter "01" to receive this software.

01. Program design

1). Realization of translation function

For this set of translation software, its core function belongs to the translation function . Here we use the " Youdao Translation " interface. The program is submitted to the interface through the construction form, and the interface will return the translation result to us. The procedure is shown in the figure below:

image

In the above program, when we construct the form, we only need to pass in the value of " type " and " i " we translated . Type represents the type of translation, such as "Chinese to Korean", "Chinese to English" and other types .

 

And i represents the content we need to translate. After constructing the form, we only need to submit the form to the interface, and the interface can return the result to us. If the call to the interface fails, the program will return " Youdao dictionary interface call failed ".

 

 

02. Interface construction

After the core content is completed, let's explain the construction of the interface. For the construction of the interface, we use tkinter to complete. In the initial interface, the program is as shown in the figure below:

image

The initial content of the interface includes the Frame frame, which is used to place the content of the text box, the drop-down menu is used to select the translation type, and the button is used to start the translation program.

To build the interface, you only need to set the position and size of each control. The overall layout of the interface is shown in the figure below.

image

For the realization of the function, you only need to click the "Translate" button in the above interface, and the function in the figure below will be automatically executed.

 

image

The above functions obtain the type of translation and the content that needs to be translated, and then call the getResult function to obtain the translation result. The translation result will be displayed in the text box on the right side of the interface.

 

03. Package software

For encapsulating programs into executable programs, here we use Pyinstaller, whose version number is 4.2, and the python version is python3.6. For software packaging, you only need to jump to the root directory of the program on the command line, and then run pyinstaller -F -w -i python.ico sofeware.py to start packaging.

The meaning of -F is to pack a single py file, the meaning of -w is to start the program without opening the command line, and the meaning of -i is to indicate that our icon is the python.ico icon. Finally, we can enter the py file we want to be encapsulated.

 

04. Summary

The above is the production of the translation software that Xiaobian brings to you today. You can download the software and apply it directly, which is convenient and affordable. Learning Python is so fun and fun!

Interested students can follow the editor and send a private letter "01" to receive this software.

Guess you like

Origin blog.csdn.net/aaahtml/article/details/113102744