迷你有道翻译源代码

今天为大家介绍一款有道翻译的软件
废话不多说,先上代码
环境:python3

import requests
from tkinter import Tk,Button,Entry,Label,Text,END

class youdaohelper(object):
    def __init__(self):
        pass
    def crawl(self,content):
        data = {
            'i': content,
            'from': 'AUTO',
            'to': 'AUTO',
            # 'smartresult':'dict',
            'client': 'fanyideskweb',
            # 'salt':'15845869423826',
            # 'sign':'9046c8954cf2d2b516552f51f65f47ed',
            'ts': '1584586942382',
            'bv': 'cc652a2ad669c22da983a705e3bca726',
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_CLICKBUTTION'
        }
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
        }
        url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
        result = requests.post(url, data, headers=headers)
        p = result.json()['translateResult'][0][0]['tgt']
        return p


class Application(object):

    def __init__(self):
        self.helper = youdaohelper()
        self.window = Tk()
        self.window.title(u'有我在手 英语无忧')
        self.window.geometry("280x350+1050+10")
        self.window.attributes('-topmost',True)
        # 输入框
        self.entry = Entry(self.window)
        self.entry.place(x=10, y=10, width=200, height=25)
        # 提交按钮
        self.submit_btn = Button(self.window, text=u'查询', command=self.submit)
        self.submit_btn.place(x=220, y=10, width=50, height=25)
        # 翻译结果标题
        self.title_label = Label(self.window, text=u'翻译结果')
        self.title_label.place(x=10, y=55, height=25)

        # 翻译结果
        self.result_text = Text(self.window, background='white')
        self.result_text.place(x=10, y=75, width=260, height=265)

    def submit(self):

        content=self.entry.get()

        p=self.helper.crawl(content)
        self.result_text.delete(1.0,END)
        self.result_text.insert(END,p)
    def run(self):
        self.window.mainloop()

if __name__=='__main__':
    app=Application()
    app.run()
运行结果如图所示
(https://img-blog.csdnimg.cn/20200327221650590.png)
[这是一直置顶的]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值