一枚丶学渣 发表于 2020-9-25 20:16:36

python

求大佬们指点!!
下面是代码:
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']['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()

Hdabo 发表于 2020-9-26 09:08:32

有奖励么。。。。。

墨锦python 发表于 2020-9-27 10:28:44

感谢鱼币
希望你的问题得到解决
页: [1]
查看完整版本: python