|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
import urllib.request
import urllib.parse
def zh_en(url):
headers = {"User-Agent" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"}
url = url + "en/"
content =e1.get(0.0,END)
data ={}
data["from"] = content
data["source"] = "1"
data = urllib.parse.urlencode(data).encode("utf-8")
response = urllib.request.urlopen(url,data)
html = response.read().decode("utf-8")
a = html.find("翻译结果")+70
b = html.find("<",a)
result = html[a:b]
e2.insert(0.0,result)
def zh_ja(url):
pass
def zh_ko(url):
pass
root = Tk()
root.title("翻译Demo")
url = "http://fanyi.zou.la/"
Label(root,text="在此输入要翻译的单词或文字:").grid(row=0,column=0)
Label(root,text="AI翻译的结果为:").grid(row=1,column=0)
e1 = Text(root,width=25,height=3)
e2 = Text(root,width=25,height=3)
e1.grid(row=0,column=1,padx=10,pady=5)
e2.grid(row=1,column=1,padx=10,pady=5)
Button(root,text="中英文互译",width=10,command=zh_en(url))\
.grid(row=3,column=0,sticky=W,padx=100,pady=10)
Button(root,text="中日文互译",width=10,command=zh_ja(url))\
.grid(row=3,column=1,sticky=E,padx=100,pady=10)
Button(root,text="中韩文互译",width=10,command=zh_ko(url))\
.grid(row=4,column=0,sticky=W,padx=100,pady=10)
Button(root,text="退出",width=10,command=root.quit)\
.grid(row=4,column=1,sticky=E,padx=100,pady=10)
mainloop()
我只试写了zh_en函数 但是我点击”中英文互译“按钮没有反应 不知道为什么 请大神指点
command=zh_en
需要传参用lambda
|
|