主程序代码:morse_query.py
#-*- coding: UTF-8 -*- __author__ = '007' __date__ = '2016/4/5' from Tkinter import * class morse2char(): char_morse = {} morse_char = {} morse_num = {} char_num = {} def __init__(self): self.root = Tk() self.root.title("MORSE码查询器") self.frm = Frame(self.root) #top Label(self.root,text="MORSE码查询器", bg="green", font=('Arial',15)).pack() self.morse_table() #left self.frm_L = Frame(self.frm) self.frm_LT = Frame(self.frm_L) self.var_char = StringVar() Entry(self.frm_LT, textvariable=self.var_char, width=5, font=('Arial',15)).pack(side=RIGHT) Label(self.frm_LT, text="字符", bg="yellow", font=('Arial',12)).pack(side=LEFT) self.frm_LT.pack(side=TOP) self.var_L_char = StringVar() self.lb_char = Listbox(self.frm_L, selectmode=BROWSE, listvariable=self.var_L_char, font =('Verdana',12), width=6, height=13) self.lb_char.bind('<ButtonRelease-1>', self.get_char) for key in self.char_num: self.lb_char.insert(END, key[0]) self.scrl_char = Scrollbar(self.frm_L) self.scrl_char.pack(side=RIGHT, fill=Y) self.lb_char.configure(yscrollcommand = self.scrl_char.set) self.lb_char.pack(side=LEFT, fill=BOTH) self.scrl_char['command'] = self.lb_char.yview self.frm_L.pack(side=LEFT) #mid self.frm_M = Frame(self.frm) self.t_show = Text(self.frm_M, width=20, height=5, font =('Verdana',15)) self.t_show.insert('1.0', '') self.t_show.pack() self.frm_MB = Frame(self.frm_M) Button(self.frm_MB, text="清除", command=self.clear, width=6, height=1, bd=3, font=('Arial', 10)).pack(side=LEFT) Button(self.frm_MB, text="查询", command=self.search, width=6, height=1, bd=3, font=('Arial', 10)).pack(side=RIGHT) self.frm_MB.pack(side=BOTTOM) self.frm_M.pack(side=LEFT) #right self.frm_R = Frame(self.frm) self.frm_RT = Frame(self.frm_R) self.var_morse = StringVar() Entry(self.frm_RT, textvariable=self.var_morse, width=5, font=('Arial',15)).pack(side=LEFT) Label(self.frm_RT, text="morse码", bg="pink", font=('Arial',12)).pack(side=RIGHT) self.frm_RT.pack(side=TOP) self.var_R_morse = StringVar() self.lb_morse = Listbox(self.frm_R, selectmode=BROWSE, listvariable=self.var_R_morse, font=('Verdana',12), width=10, height=13) self.lb_morse.bind('<ButtonRelease-1>',self.get_morse) for key in self.morse_num: self.lb_morse.insert(END,key[0]) self.scrl_morse = Scrollbar(self.frm_R) self.scrl_morse.pack(side=RIGHT,fill=Y) self.lb_morse.configure(yscrollcommand=self.scrl_morse.set) self.lb_morse.pack(side=LEFT,fill=BOTH) self.scrl_morse['command'] = self.lb_morse.yview self.frm_R.pack(side=LEFT) self.frm.pack() def get_char(self, event): self.var_char.set('') self.var_morse.set('') tmp = self.lb_char.get(self.lb_char.curselection()) self.var_char.set(tmp) def get_morse(self, event): self.var_morse.set('') self.var_char.set('') tmp = self.lb_morse.get(self.lb_morse.curselection()) self.var_morse.set(tmp) def clear(self): self.var_char.set('') self.var_morse.set('') self.t_show.delete('1.0','10.0') def search(self): self.t_show.delete('1.0','10.0') tmp_char = self.var_char.get().upper() tmp_morse = self.var_morse.get() if tmp_char != '': if not self.char_morse.has_key(tmp_char): self.t_show.insert('1.0','您输入的字符不在查询范围内!') else: self.t_show.insert('1.0','morse码:' + ' ' + self.char_morse[tmp_char][0:] + ' ') elif tmp_morse != '': if not self.morse_char.has_key(tmp_morse): self.t_show.insert('1.0','您输入的morse码不在查询范围内') else: self.t_show.insert('1.0','字符:' + ' ' + self.morse_char[tmp_morse][0] + ' ') else: self.t_show.insert('1.0',"请选择或输入") self.var_char.set('') self.var_morse.set('') def morse_table(self): f = file('./morse_query') for line in f: chunk = line.strip().split(' ') #print chunk self.char_morse[chunk[0]] = chunk[1] self.morse_char[chunk[1]] = chunk[0] self.char_num = sorted(self.char_morse.iteritems(), key = lambda asd:asd[1]) self.morse_num = sorted(self.morse_char.iteritems(), key = lambda asd:asd[0]) def main(): m = morse2char() mainloop() if __name__ == "__main__": main()
文件:morse_query
A .- B -... C -.-. D -.. E . F ..-. G --. H .... I .. J .--- K -.- L .-.. M -- N -. O --- P .--. Q --.- R .-. S ... T - U ..- V ...- W .-- X -..- Y -.-- Z --.. 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. 0 ----- . .-.-.- : ---... , --..-- ; -.-.-. ? ..--.. = -...- ' .----. / -..-. ! -.-.-- - -....- _ ..--.- " .-..-. ( -.--. ) -.--.- $ ...-..- & .... @ .--.-.
py转换为exe:setup_morse_q.py
#-*- coding: UTF-8 -*- __author__ = '007' __date__ = '2016/4/7' from distutils.core import setup import py2exe setup(windows=['morse_query.py'],options={"py2exe":{"dll_excludes":["MSVCP90.dll"]}})
morse_query.exe
下载: (提取码:6216)