Skip to content

Instantly share code, notes, and snippets.

@basictomonokai
Created December 9, 2017 08:26
Show Gist options
  • Save basictomonokai/9cc69e73e36478c8aee7ae46964fd1ec to your computer and use it in GitHub Desktop.
Save basictomonokai/9cc69e73e36478c8aee7ae46964fd1ec to your computer and use it in GitHub Desktop.
英単語辞書のpythonプログラム
from tkinter import *
import win32api
## 検索関数
def click():
## 入力用インプットボックスから検索文字列を取得
entered_text=textentry.get()
## 入力チェック
if entered_text == "":
## ダイアログの呼び出し
win32api.MessageBox(0, '検索文字列が空です', '辞書ツール', 0x00000030)
return
## 結果表示用テキストボックスのクリア
output.delete(0.0,END)
# 辞書ファイルを開く
dic = open("ejdic-hand-utf8.txt","rt",encoding="utf-8")
# 結果表示用変数のクリア
result_area = ""
# 辞書ファイルをループ検索
for line in dic:
if line.startswith(entered_text):
result_area = result_area+line+"\n"
# 結果表示用変数が空のままなら該当なしをセット
if result_area == "":
result_area = "検索文字列( "+entered_text+ ")がみつかりません"
# 辞書ファイルのクローズ
dic.close()
# 結果を表示用テキストボックスにセット
output.insert(END,result_area)
## 検索関数
def clear_area():
## 入力用インプットボックスのクリア
textentry.delete(0,END)
## 結果表示用テキストボックスのクリア
output.delete(0.0,END)
## メインウィンドウの準備
win = Tk() # ウィンドウを作成
win.title(u"英単語辞典V1.0")
win.geometry("800x500")
win.configure(bg="black")
## ロゴマーク
photo1 = PhotoImage(file="DesignEvo.png")
Label (win,image=photo1,bg="black").grid(row=0,column=0,sticky=W)
## 入力用インプットボックスのラベル
Label (win,text="検索する英単語",bg="black",fg="white",font="none 18 bold").grid(row=1,column=0,sticky=W)
## 入力用インプットボックス
textentry = Entry(win,width=20,bg="white",font="none 14")
textentry.grid(row=2,column=0,sticky=W)
## 検索用のボタン
Button(win,text="検索",width=10,command=click).grid(row=3,column=0,sticky=W)
## クリア用のボタン
Button(win,text="クリア",width=10,command=clear_area).grid(row=4,column=0,sticky=W)
## 結果表示用テキストボックスのラベル
Label (win,text="\n検索結果表示欄",bg="black",fg="white",font="none 18 bold").grid(row=5,column=0,sticky=W)
## 結果表示用テキストボックス
output = Text(win,width=75,height=6,wrap=WORD,bg="white",font="none 14")
output.grid(row=6,column=0,columnspan=2,sticky=W)
## 終了ラベル
Label (win,text="英単語辞典の終了",bg="black",fg="white",font="none 18 bold").grid(row=7,column=0,sticky=W)
## 終了ボタンを押した時に呼び出す関数
def close_window():
win.destroy()
exit()
## 終了ボタン
Button(win,text="終了",width=10,command=close_window).grid(row=8,column=0,sticky=W)
win.mainloop() # イベントループを実行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment