python项目之 英汉词典 带GUI tkinter
2016-01-10 16:51
761 查看
python项目之 英汉词典 带GUI tkinter
思路
从文本中读取全部单词,然后和输入的词对比,有的话就输出中文的释义。知识点
文本读取类和对象的使用
GUI界面的搭建,使用tkinter
成品如下
词库的链接
http://pan.baidu.com/s/1jHw2n0y源码如下
[code]# -*- coding: utf-8 -*- ################################### ##coding by 刘云飞 ################################### import os import sqlite3 from tkinter import * class One_Word(object): def __init__(self): self.en = u"" self.num = 0 self.chs = [] def set_word(self, en, num, chs): self.num = num self.chs = chs self.en = en def read_file(): words =[] with open('wwaa.txt','r',encoding='utf8') as f: while True: line = f.readline().strip('\n') if line == "": break wod = line.split("=") en = wod[1] nums = f.readline().strip('\n').split("=") num = int(nums[1]) i=0 chs = [] while i< num: f.readline() chs.append(f.readline().strip('\n')) i += 1 word= One_Word() word.en = en word.chs = chs word.num = num words.append(word) return words def cha_xun(danci,words): flag = False chs = "" for word in words: if flag == True: break if danci == str(word.en): num = word.num chss = word.chs flag =True for chsa in chss: chs += chsa chs +="\n" return chs def get_word(): w_en = ent_cha.get() #print(w_en) chs = cha_xun(w_en,words) if chs == "": strs = "Not find word ->"+ w_en text_chs.set(strs) else: text_chs.set(chs) words = read_file() gui = Tk() gui.title('英汉词典 by 刘云飞') gui.geometry('600x480') lab_cha = Label(gui,text = "查询:",font = 'Times -20',\ width = 8,height = 2) ent_cha = Entry(gui,font = 'Times -20',width = 40) lab_shiyi = Label(gui,text = "释义:",font = 'Times -20',\ width = 8,height = 2) text_chs = StringVar() ent_shiyi = Label(gui,textvariable =text_chs,\ font = '宋体 -20',bg = 'white',\ width = 40,height = 17) lab_cha.grid(row = 0,column = 0) ent_cha.grid(row = 0,column = 1) lab_shiyi.grid(row = 1,column = 0) ent_shiyi.grid(row = 1,column = 1) labss = Label(gui,text = "",font = 'Times -20',\ width = 1,height = 1) labss.grid(row = 2,column = 0) btn_cha = Button(gui,text = "查询",command = get_word,\ font = 'Times -20',width = 10,height = 1) btn_cha.grid(row = 3,column = 1) gui.mainloop()
相关文章推荐
- 使用python 加载tkdnd 的库(_load_tkdnd : _tkinter.TclError: couldn't load library )的时候错误的解决措施
- python入门笔记(Day5)--filter,sorted,lambda,装饰,偏,模块
- python 进度条 tqdm
- python之路-模块 splinter
- 关于python format()用法详解
- Python爬虫入门案例:获取百词斩已学单词列表
- Python访问Access数据库的需要注意的几点
- 从PCA到Kernel PCA(Python)
- python安装twisted遇到的问题
- Python/C API 抽象对象层(部分)
- 飘逸的python - yield简明教程
- NumPy学习 -- 002_常用函数
- python学习笔记二之数据类型(基础篇)
- leetcode之Maximum Subarray
- win7安装pycharm5+pyqt5+python3.4
- 《笨办法学Python》 第10课手记
- Ubuntu 14.04下搭建Python3.4 + PyQt5.3.2 + Eric6.0开发平台
- python小白-day2 基本数据类型
- [python]自问自答:python -m参数?
- python基础知识-数字