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

How to make a screen translation tool for Python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Python how to make screen translation tool, in view of this question, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

1. Scene

If you usually encounter English you don't know, I believe most people will copy the content and use translation software, or copy it to the website to perform translation.

Of course, for IDE, browsers can install some plug-ins to translate, youdao also has cross-word translation.

However, there are often parsing dialogs that are unable to copy the text, and the above methods become at a loss.

Today, we will teach you to use 10 lines of Python code to make a flip-screen software that can be translated everywhere and work efficiently.

two。 Implementation steps

First, we use the PIL dependent library clipboard to read the image and then download it locally.

# install PIL dependency

# read pictures from the clipboard img = ImageGrab.grabclipboard ()

# Save to local

Image_result ='. / temp.png'

Img.save (image_result)

Next, use the OCR function of the pytesseract dependent library to identify the English content in the picture.

# OCR recognition

# identify the English in the picture

Content_eng = pytesseract.image_to_string (Image.open (image_result), lang='eng')

Then, it is to translate the English content identified above.

In order to ensure the accuracy of English translation, the simple dependent library of Google translation: googletrans is used here.

# Translation

# Google Translation

Translator = Translator (service_urls= ['translate.google.cn'])

# translate into Chinese

Content_chinese = translator.translate (content_eng, src='en', dest='zh-cn') .text

Finally, the recognized Chinese is displayed by using the GUI tkinker that comes with Python.

# initialization

Root = Tk ()

Root.withdraw ()

# display the translated results in the form of a dialog box

Tkinter.messagebox.showinfo ('translation result', content_chinese) 3. Simplify the steps

To speed up the translation process, save the above script locally, and then set a shortcut to execute the script.

On the PC side, you can package it into EXE and set shortcut keys, or use WinHotKey to set up script execution.

MAC OSX, using automatic operation (run Shell script) + keyboard shortcut (service), you can execute the script quickly.

In this way, only screenshots and keyboard shortcuts are needed, and the translation operation is performed quickly in two steps.

This is the answer to the question about how to make the screen translation tool made by Python. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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

Internet Technology

Wechat

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

12
Report