猫史档案馆


【福利】哈哈我来送代码啦

用户:印泽恩Tim印泽恩Tim查看:2 回复:5 评论:2 创建时间:2018-12-15T11:02:38


大家好,我是印度大象,没错,我又来送代码啦

什么?你不知道我有送过代码?

https://www.codemao.cn/community/168494

这是上期的链接

拿走不送

因为发不了文件,只能发代码啦

from tkinter import *     # all 模块
from tkinter import messagebox
import requests
#根据用户输入的单词翻译
def translation():
	# 获取用户输入的单词
	content = entry.get()
	if content == '':
		messagebox.showinfo('提示','请输入要翻译的单词')
	else :
		url = 'http://fanyi.youdao.com/translate?喵artresult=dict&喵artresult=rule'
		headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win喵; x喵; rv:57.0) Gecko/20100101 Firefox/57.0'}
		data = {}
		data['i'] = content
		data['from'] = 'AUTO'
		data['to'] = 'AUTO'
		data['喵artresult'] = 'dict'
		data['client'] = 'fanyideskweb'
		#时间戳
		#data['salt'] = '1543039222701'
		# 签名 加密的
		#data['sign'] = '4691d0a1d627a09b3f42aa732e15c482'
		
		data['doctype'] = 'json'
		data['version'] = '2.1'
		data['keyfrom'] = 'fanyi.web'
		data['action'] = 'FY_BY_REALTIME'
		data['typoResult'] = 'false'

		result = requests.post(url, data=data, headers = headers)
		translation = result.json()
		translation = translation['translateResult'][0][0]['tgt']
		#print(translation)
		res.set(translation)

# 创建窗口
root = Tk()
# 窗口标题
root.title('中英互译')
# 窗口大小  小写x
root.geometry('387x95+500+300')
# 窗口位置
# root.geometry('+500+300')
# 标签控件
lable = Label(root, text = '请输入要翻译的文字:',font = ('微软雅黑'))
lable.grid(row = 0,column = 0)
lable1 = Label(root,text = '翻译之后的结果:',font=('微软雅黑'))
#网格式布局 pack 包 place 位置
lable1.grid(row = 1,column = 0)

# 变量
res = StringVar()
# 输入控件
entry = Entry(root,font = ('微软雅黑',14))
entry.grid(row = 0,column = 1)
# 翻译之后的结果
entry1 = Entry(root,font = ('微软雅黑',14), textvariable = res)
entry1.grid(row = 1,column = 1)

# 按钮控件
button = Button(root,text = '翻译',width = 10,font = ('微软雅黑',10), command = translation)
# sticky 对齐方式 N S E W  上下左右
button.grid(row = 2,column = 0, sticky = W)
button1 = Button(root,text = '退出',width = 10,font = ('微软雅黑',10), command = root.quit)
button1.grid(row = 2,column = 1,sticky = E)
# 消息循环 显示窗口
root.mainloop()

 

运行一下这些代码 看看有什么效果 再截图发到本帖下方 哈哈 第一个截图的可以再获得一个代码文件哦


回复

上一页1 页 / 共 1下一页
Ryan袁奥Ryan袁奥

center_image

点赞0


评论


Ryan袁奥Ryan袁奥

emotion_编程猫_点赞

点赞0


评论


Ryan袁奥Ryan袁奥

QQ:2168480491

点赞0


评论


Ryan袁奥Ryan袁奥

代码给我~

点赞0


评论


印泽恩Tim印泽恩Tim

恭喜Ryan袁奥成为第一个发送出代码效果的训练师 记得看qq哦 收到代码文件记得在社区发出效果哦

点赞0


评论