鱼C论坛

 找回密码
 立即注册
查看: 2172|回复: 3

[作品展示] 爬有道翻译的的一个程序+tkinter界面

[复制链接]
发表于 2020-8-30 12:21:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
from tkinter import *
import urllib.request
import urllib.parse
import json
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'

root = Tk()
root.title('翻译')

Label(root,text='请输入:').grid(row=0,column=0,padx=10,pady=10)
Label(root,text='翻译结果:').grid(row=3,column=0,padx=10,pady=10)



e1 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e1.grid(row=0,column=1)


e2 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e2.grid(row=4,column=1)


def tr():
    e2.delete(1.0, END)
    temp = e1.get(1.0, END)
    date = {}
    date['i'] = temp
    date['from']='AUTO'
    date['to']='AUTO'
    date['smartresult']='dict'
    date['client']='fanyideskweb'
    date['salt']='15979913254708'
    date['sign']='fe5f00b4f6da188ae071a5f15f239354'
    date['lts']='1597991325470'
    date['bv']='cc652a2ad669c22da983a705e3bca726'
    date['doctype']='json'
    date['version']='2.1'
    date['keyfrom']='fanyi.web'
    date['action']='FY_BY_CLICKBUTTION'
    date = urllib.parse.urlencode(date).encode('utf-8')
    response = urllib.request.urlopen(url,date)
    html = response.read().decode('utf-8')

    target = json.loads(html)
    target = target['translateResult'][0][0]['tgt']
    e2.insert(INSERT,(target))


b2=Button(root,text='翻译',width=10,command=tr)
b2.grid(row=0,column=3,padx=10,pady=10)


b1=Button(root,text='退出',width=10,command=root.quit)
b1.grid(row=5,column=3,padx=10,pady=10)

def empty():
    e1.delete(1.0, END)


b3=Button(root,text='清空',width=10,command=empty)
b3.grid(row=3,column=3,padx=10,pady=10)




mainloop()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-9-1 17:03:27 | 显示全部楼层
2.0 版本
from tkinter import *
import urllib.request
import urllib.parse
import json
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'

root = Tk()
root.title('翻译')




def tr(event):
    e2.delete(1.0, END)
    event = e1.get(1.0, END)
    date = {}
    date['i'] = event
    date['from']='AUTO'
    date['to']='AUTO'
    date['smartresult']='dict'
    date['client']='fanyideskweb'
    date['salt']='15979913254708'
    date['sign']='fe5f00b4f6da188ae071a5f15f239354'
    date['lts']='1597991325470'
    date['bv']='cc652a2ad669c22da983a705e3bca726'
    date['doctype']='json'
    date['version']='2.1'
    date['keyfrom']='fanyi.web'
    date['action']='FY_BY_CLICKBUTTION'
    date = urllib.parse.urlencode(date).encode('utf-8')
    response = urllib.request.urlopen(url,date)
    html = response.read().decode('utf-8')

    target = json.loads(html)
    target = target['translateResult'][0][0]['tgt']
    e2.insert(INSERT,(target))

   

e1 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e1.pack(fill=X)
e1.bind('<KeyRelease>',tr)
e1.focus_set()


e2 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e2.pack(fill=X)


def empty():
    e1.delete(1.0, END)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-1 17:04:34 | 显示全部楼层
2.0版本
from tkinter import *
import urllib.request
import urllib.parse
import json
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'

root = Tk()
root.title('翻译')




def tr(event):
    e2.delete(1.0, END)
    event = e1.get(1.0, END)
    date = {}
    date['i'] = event 
    date['from']='AUTO'
    date['to']='AUTO'
    date['smartresult']='dict'
    date['client']='fanyideskweb'
    date['salt']='15979913254708'
    date['sign']='fe5f00b4f6da188ae071a5f15f239354'
    date['lts']='1597991325470'
    date['bv']='cc652a2ad669c22da983a705e3bca726'
    date['doctype']='json'
    date['version']='2.1'
    date['keyfrom']='fanyi.web'
    date['action']='FY_BY_CLICKBUTTION'
    date = urllib.parse.urlencode(date).encode('utf-8')
    response = urllib.request.urlopen(url,date)
    html = response.read().decode('utf-8')

    target = json.loads(html)
    target = target['translateResult'][0][0]['tgt']
    e2.insert(INSERT,(target))

    

e1 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e1.pack(fill=X)
e1.bind('<KeyRelease>',tr)
e1.focus_set()


e2 =Text(root,width=40,height=5,font=("宋体", 18, "bold"))
e2.pack(fill=X)


def empty():
    e1.delete(1.0, END)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2021-11-16 16:18:32 | 显示全部楼层
支持楼主
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-12 19:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表