Skip to content

Instantly share code, notes, and snippets.

@renyuanL
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renyuanL/8595c4c5a8e5f44ecf76 to your computer and use it in GitHub Desktop.
Save renyuanL/8595c4c5a8e5f44ecf76 to your computer and use it in GitHub Desktop.
ryGlossary_Final.py
'''
ryGlossary_Final.py
查詞彙.py
呂仁園,2014/07/09
'''
from tkinter import *
窗類= Tk
輸入類= Entry
文字類= Text
標籤類= Label
按鈕類= Button
#
# 創造 視窗應用程式的元件(widget)。
#
窗= 窗類()
窗.title("查詞彙")
輸入框= 輸入類(窗, bg= "cyan")
輸出框= 文字類(窗, bg= "yellow")
輸入框標籤= 標籤類(窗, text= "輸入你要找的詞彙:")
輸出框標籤= 標籤類(窗, text= "查詢結果如下:")
def 點擊查詢():
輸入文字= 輸入框.get()
try:
詞彙定義= 詞彙表[輸入文字]
#
# 輸入文字若在詞彙表中找不到,
# 程式會在此發生「意外」(except),
# 就進入下一行的 except: 之內。
#
except:
詞彙定義 = "這個字詞 【%s】 找不到。"%(輸入文字)
輸出框.delete(0.0, END)
輸出框.insert(END, 詞彙定義)
按鈕= 按鈕類(窗, text= "點擊查詢", command= 點擊查詢)
#
# 安排元件的位置
#
輸入框標籤.grid(row=0,column=0); 輸入框.grid(row=0,column=1)
輸出框標籤.grid(row=1,column=0); 按鈕.grid( row=1,column=1)
輸出框.grid( row=2,column=0, columnspan= 2)
#
# 詞彙表 資料庫 在此,
# 通常我們可以上網取得這種資料,
# 略加整理成我們要的格式。
#
詞彙表= {
'台灣': 'Taiwan',
'美國': 'USA',
'日本': 'Japan',
'中國': 'China',
'Taiwan': '台灣',
'USA': '美國',
'Japan': '日本',
'China': '中國'}
#
# 進入主迴圈
#
窗.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment