|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求大佬们指点!!
下面是代码:
from tkinter import *
import urllib.parse
import urllib.request
import json
s=''
def gets():
global s
content=a
url='http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
data={}
data['i']= content
data['from']= 'AUTO'
data['to']= 'AUTO'
data['smartresult']= 'dict'
data['client']= 'fanyideskweb'
data['salt']= '16010215344356'
data['sign']= '69394bd2122d2c170fd0fb97554dfc1d'
data['lts']= '1601021534435'
data['bv']= 'b396e111b686137a6ec711ea651ad37c'
data['doctype']= 'json'
data['version']= '2.1'
data['keyfrom']= 'fanyi.web'
data['action']= 'FY_BY_REALTlME'
data=urllib.parse.urlencode(data).encode('utf-8')
response = urllib.request.urlopen(url,data)
html=response.read().decode('utf-8')
target = json.loads(html)
s=target['translateResult'][0][0]['tgt']
print(html)
root = Tk()
Label(root,text="请输入翻译内容:").grid(row=0,column=0)
Label(root,text="翻译结果:").grid(row=1,column=0)
text1=Entry(root)
text1.grid(row=0,column=1,padx=10,pady=5)
a=text1.get()
text2=Text(root,width=20,height=2)
text2.grid(row=1,column=1)
def Reset():
global s
text2.delete(1.0, END)
text2.insert(INSERT,s)
def translation():
global s
Reset()
gets()
print(html)
b= Button(root,text="翻译", command=translation)
b.grid(row=2,column=2)
mainloop() |
-
|