python-Morse Code Finder

Source: Internet
Author: User

Main program code:morse_query.py

#-*-coding:utf-8-*-__author__='007'__date__='2016/4/5'    fromTkinterImport*classMorse2char (): Char_morse={} Morse_char={} morse_num={} char_num= {}    def __init__(self): Self.root=Tk () self.root.title ("Morse Code Finder") Self.frm=Frame (self.root)#TopLabel (self.root,text="Morse Code Finder", bg="Green", Font= ('Arial', 15) . Pack () self.morse_table ()# Leftself.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', ()). Pack (side=Right ) Label (self.frm_lt, Text="character", bg="Yellow", Font= ('Arial', ()). 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', Width=6, height=13) Self.lb_char.bind ('<ButtonRelease-1>', Self.get_char) forKeyinchSelf.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 )#MidSelf.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="Clear", Command=self.clear, Width=6, Height=1, bd=3, font= ('Arial'). Pack (side=Left ) Button (SELF.FRM_MB, Text="Enquiry", Command=self.search, Width=6, Height=1, bd=3, font= ('Arial'). Pack (side=Right ) Self.frm_MB.pack (Side=BOTTOM) self.frm_M.pack (Side=Left )# RightSelf.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', ()). Pack (side=Left ) Label (self.frm_rt, Text="Morse yards", bg="Pink", Font= ('Arial', ()). 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', width=10, height=13) Self.lb_morse.bind ('<ButtonRelease-1>', Self.get_morse) forKeyinchSelf.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 ()defGet_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)defGet_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)defClear (self): Self.var_char.set ("') Self.var_morse.set ("') Self.t_show.delete ('1.0','10.0')    defSearch (self): Self.t_show.delete ('1.0','10.0') Tmp_char=self.var_char.get (). Upper () Tmp_morse=Self.var_morse.get ()ifTmp_char! ="':            if  notSelf.char_morse.has_key (Tmp_char): Self.t_show.insert ('1.0','the character you entered is not within the scope of the query!')            Else: Self.t_show.insert ('1.0','Morse Code:'+'\ t'+ self.char_morse[tmp_char][0:] +'\ n')        elifTmp_morse! ="':            if  notSelf.morse_char.has_key (tmp_morse): Self.t_show.insert ('1.0','The Morse code you entered is not within the scope of the query')            Else: Self.t_show.insert ('1.0','characters:'+'\ t'+ self.morse_char[tmp_morse][0] +'\ n')        Else: Self.t_show.insert ('1.0',"Please select or enter") Self.var_char.set ("') Self.var_morse.set ("')    defmorse_table (self): F= File ('./morse_query')         forLineinchF:chunk= Line.strip (). Split ('  ')            #Print ChunkSelf.char_morse[chunk[0]] = chunk[1] self.morse_char[chunk[1]] =Chunk[0] Self.char_num= Sorted (Self.char_morse.iteritems (), key =LambdaAsd:asd[1]) Self.morse_num= Sorted (Self.morse_char.iteritems (), key =Lambdaasd:asd[0])defMain (): M=Morse2char () mainloop ( )if __name__=="__main__": Main ()

Files: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 conversion to EXE:setup_morse_q.py

#-*-coding:utf-8-*-__author__='007'__date__='2016/4/7' fromDistutils.coreImportSetupImportpy2exesetup (Windows=['morse_query.py'],options={"Py2exe":{"Dll_excludes":["MSVCP90.dll"]}})

Morse_query.exe

Download: (Extract code: 6216)

python-Morse Code Finder

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.