python-摩爾斯電碼查詢器

來源:互聯網
上載者:User

標籤:

主程式碼: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碼:‘ + ‘\t‘ + self.char_morse[tmp_char][0:] + ‘\n‘)        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‘,‘字元:‘ + ‘\t‘ + self.morse_char[tmp_morse][0] + ‘\n‘)        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 setupimport py2exesetup(windows=[‘morse_query.py‘],options={"py2exe":{"dll_excludes":["MSVCP90.dll"]}})

morse_query.exe

下載: (提取碼:6216)

python-摩爾斯電碼查詢器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.