# -*- coding: utf-8 -*-
\"\"\"
Created on Tue Dec 18 01:06:45 2018

@author: Administrator
\"\"\"

#导入模块
import tkinter

#创建窗口
window = tkinter.Tk()

#设置窗口属性
window.geometry(\"500x300\")
window. (\"英汉词典\")
window.resizable(width=True,height=False)

#输入框布局
input_  = tkinter. (window,width=30,height=30)
input_ .pack(side=\"top\")

#输入框
entry = tkinter.Entry(input_ ,width=30)
entry.pack(side=\"left\")

# 可以向entry预设提示信息(用字典讲歌词存储起来)
file00 = open(\"C:\\\\Users\\\\Administrator\\\\dict.txt\", \"r\", encoding=\"utf-8\")
content = file00.read()
content.strip()
list00 = content.splitlines()
dict00 = {}
for i in list00:
    list01 = i.split(\"\\t\")
    for j in range(len(list01) - 1):
        if list01[j]:
            dict00[list01[j]] = list01[-1]

#显示数据
def show_info():
    if entry.get() in dict00:
        text.insert(tkinter.INSERT, dict00[entry.get()] + \"\\n\")
    else:
        result = entry.get()
        result = \"该词汇尚未录入,敬请期待!\"
        text.insert(tkinter.INSERT, result+ \"\\n\")

#显示按钮
button = tkinter.Button(input_ ,text=\"查询\",command=show_info,bg=\"yellow\")
button.pack(side=\"left\")

#退出按钮
quit_btn = tkinter.Button(input_ ,text=\"退出\",bg=\"red\",command=window.quit)
quit_btn.pack(side=\"right\")

#文本框
text = tkinter.Text(window,width=68,height=20,bg=\"yellow\")
text.pack(side=\"bottom\")

#清空数据
def clear_info():
    text.delete(0.0,tkinter.END)

#清空按钮
clear_btn = tkinter.Button(input_ ,text=\"清空\",bg=\"blue\",command=clear_info)
clear_btn.pack()

#循环消息
window.mainloop()

\"在这里插入图片描述\"

收藏 打印