#导入模块 import tkinter #创建窗口 window = tkinter.Tk() #设置窗口属性 window.geometry("500x300") window.title("英汉词典") window.resizable(width=True,height=False) #输入框布局 input_frame = tkinter.Frame(window,width=30,height=30) input_frame.pack(side="top") #输入框 entry = tkinter.Entry(input_frame,width=30) entry.pack(side="left") # 可以向entry预设提示信息(用字典讲歌词存储起来) file00 = open("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_frame,text="查询",command=show_info,bg="yellow") button.pack(side="left") #退出按钮 quit_btn = tkinter.Button(input_frame,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_frame,text="清空",bg="blue",command=clear_info) clear_btn.pack() #循环消息 window.mainloop()
python小项目--》英汉互译词典
猜你喜欢
转载自blog.csdn.net/qq_42336700/article/details/81460549
今日推荐
周排行