Introduction:

Learning English is hard, but it’s fun. ———— That thing about learning English

Do you have the need to read the original English web pages, news and literature? Do you always have to stop and look up the dictionary, stumble, or find it difficult to continue reading?

Xiaobian often encounter this problem, although learning Python English is enough, but it seems to need to be better at home, the children at home often let me help to complete her homework, to tell the truth, very angry ah? The translation of a single individual is also good, even the translation can not come out…….

This edition of xiaobian would like to recommend a translation of black technology AIDS, can help you slowly learn English ~

It can not only help you to translate Chinese, but also English, hey hey! Then quickly follow xiaobian to try it!

The body of the

This article is based on Tkinter interface small procedures oh! Follow Me

The interface selected here is youdao Translation drop link:fanyi.youdao.com/

(1) Send requests to web pages.

class YouDao(object): def __init__(self): pass def crawl(self, content): LTS = int(time.time() * 1000) # convert timestamp to ms Timestamp = LTS + random. Randint (0, 10) # sign: n.md5("fanyideskweb" + e + i + "Tbh5E8=q6U3EXe+&L[4c@") a = "fanyideskweb" e = content i = str(timestamp) d = "Tbh5E8=q6U3EXe+&L[4c@" sign = hashlib.md5((a+e+i+d).encode('utf-8')).hexdigest() data = { 'i': content, 'from': 'AUTO', 'to': 'AUTO', 'smartresult': 'dict', 'client': 'fanyideskweb', 'salt': timestamp, 'sign': sign, 'lts': LTS, 'bv' : 'dd67d51c2bbb03cccdbcfa48735ba27f', 'a doctype' : 'json', 'version' : '2.1', 'keyfrom' : 'fanyi. Web', 'the action: 'FY_BY_CLICKBUTTION' } data = urllib.parse.urlencode(data).encode('utf-8') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', 'Cookie': 'OUTFOX_SEARCH_USER_ID = 406040753 @221.204.120.171; DICT_UGC = be3af0da19b5c5e6aa4e17bd8d90b28a |; JSESSIONID = abcJcdIfpYuE3eNgyi3Dx OUTFOX_SEARCH_USER_ID_NCOO = 902501357.1460881; user-from=http://www.youdao.com/; from-page=http://www.youdao.com/; _ntes_nnid e8175b6796101a34821527eb62 = 250706, 1612611490655;  DICT_SESS=v2|qKlfGGGmbVOAOfp40fQy0UWhfPuOMzWRlfk4Qz0LYERTu0flfn4Ul0l50He40fOW0TK6LlWRf6B0w46LYmh46F0JShMTLOfOm0;  DICT_LOGIN=1||1612612510172;  STUDY_SESS=EtwvT8KhyXqnLv8r0zdde8FcMOICmtZSIsltEiKZiAQq44wPVNN6PupszWYKIkBKfygQdvKlXU7p3aF+p0H6VcZLod3s2Bld6H/EWIphmRS9 2qG/3vVhSxHFAXq2yJp8QyH/R6RElNstKdVewVkZp+NyGWhzlamzU5dl6aBiyQ2Ybdo8MpdaPQB26wR6JPAU+P6MxCmnJEvne6pPMc9TTJJnThNrM7aj0X5L VpSBvjZ0h3M1drl4ZsmtkumIhrpyk1pBNevj8UEmS52Cj8DFo+yez89Xrbg4rxsvfSmuH21KlOh/Gwx6G1S/X4FQ7qd/Z2lDsk6Qgl21Md/1bCxa/orloi9q ObM4N2yVCVhvkDdg5ILQezB8iskCpUa+ESZk; STUDY_INFO=UID_10AE81F6EF9DD9807BAC3FF3FD6407BA|4|1456638755|1612612364854;  ___rl__test__cookies=1612663596564', 'Referer': 'http://fanyi.youdao.com/', } request = urllib.request.Request('http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule', method='POST', data=data, headers=headers) response = urllib.request.urlopen(request) result_str = response.read().decode('utf-8') result_dict = json.loads(result_str) result = result_dict["translateResult"][0][0]["tgt"] return resultCopy the code

(2) Set the interface window data.

class Application(object): def __init__(self): # Create a window self.window = Tk() # create a window self.window = Tk() # create a window self.window = Tk() # create a window self.window = Tk() # create a window self.window = Tk() # create a window self.window Self.entry = entry (self.window) self.entry. Place (x=10, y=10, width=200, height=25) # width= width, Self. Button = button (self. Window, text=u', The command = self. Function) # command execute the command Perform this function self. Button. Place (x = 220, y = 10, width = 50, Self. label = label (self.window, text=u') Self.label. Place (x=10, y=45) # self.label. Place (x=10, y=45) # self.label. Place (x=10, y=45) # label. y=75, width=260, height=265)Copy the code

(3) Storage of translation results.

def function(self): Crawl (content) # Get the user's value from the input box content = self.entry.get() # send the value to the Youdao server for translation youDao = YouDao() result = Youdao.crawl (content) # Place the result in the translation box Self.text.delete (1.0, END) # self.text.insert(END, result) # def run(self): self.text.delete(1.0, END) # def run(self): self.window.mainloop()Copy the code

(4) Screenshot effect of interface translation program.

“I am too easy to be satisfied, for example, the sky is blue, the clouds are white, so happy, feeling that everything becomes very beautiful. “

‘It was sunny and very hot today,I got up early.’

conclusion

Ha ha ha! This article is written here, this translation small software home English is not good children can take to use, learning more easily ~

Free source code collection:

For complete project source code + source material base see: # private letter xiaobian 06# or click on the blue text to add you can get free benefits!

Your support is my biggest motivation!! Mua welcomes you to read the previous article

Recommended reading —

Project 1.7 Love Anniversary

Four seasons: “Only xx years to a hundred years of harmony.” How many? Just check it out.

Item 1.8 Forbidden City, it’s snowing

The Palace Museum, snow 】 Wake up one night, the Palace Museum completed the transition of autumn and winter, from the north of the story have snow and come (containing many sources)

Item 1.3 Video player

I used Python’s promised ad-free video player and wanted to go crazy for it

Item 3.2 Automatic Wallpaper change

Your computer automatically changes your wallpaper every day. This is for you.

Item 3.3 Artistic signature

Art character signature generator 】 【 】 the paper had been abandon your signature | “I think I can salvage once again, ok for you? “

Article summary —

The article summary | Python 1.0-2021 | has continuously updated, direct look at this article is enough

More content + source code in the article summary oh!! Welcome to read ~)