Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python Tkinter를 사용한 단어 사전


이 기사에서는 PyDictionary와 TkinterModule을 사용하여 GUI 기반 사전을 만들 것입니다.

PyDictionary는 단어의 의미 번역, 반의어 및 동의어를 얻는 데 도움이 되는 Python 모듈입니다. WordNet을 사용합니다. 의미를 얻으려면 Google 번역을, 동의어와 반의어를 얻으려면 synonym.com을 이용하세요. PyDictionary는 BeautifulSoup, Requests 모듈을 종속성으로 사용합니다.

애플리케이션을 만들기 위해 먼저 pip install PyDictionary를 사용하여 환경에 이러한 모듈을 설치합니다.

설치 후 tkinter 프레임 및 기타 요소를 생성합니다.

예시

# Import Required Librares
from tkinter import *
from PyDictionary import PyDictionary

# Create instances and objests
dictionary = PyDictionary()
win =Tk()

#Define the size of the window
win.geometry("700x400")

win.title("Python Dictionary")

#Define Helper Function to use the other atributes of PyDictionary Class
def dict():
   meaning.config(text=dictionary.meaning(word.get())['Noun'][0])

#Define Labels and Buttons
Label(win, text="Dictionary", font=("Times New Roman" ,20)).pack(pady=20)

# Frame 1
frame = Frame(win)
Label(frame, text="Type any Word ", font=("Poppins bold", 15)).pack(side=LEFT)
word = Entry(frame, font=("Times New Roman", 15))
word.pack()
frame.pack(pady=10)
# Frame 2
frame1 = Frame(win)
Label(frame1, text="Meaning:", font=("Aerial", 18)).pack(side=LEFT)
meaning = Label(frame1, text="", font=("Poppins",15), width= 30)
meaning.pack()
frame1.pack(pady=10)

Button(win, text="Find", font=("Poppins bold",15), command=dict).pack()

# Execute Tkinter
win.mainloop()

출력

위의 코드를 실행하면 사전 애플리케이션이 생성되고 표시됩니다. 그러나 PyDictionary를 사용하여 동의어, 반의어 찾기 등과 같은 다른 속성을 추가할 수 있습니다.

Python Tkinter를 사용한 단어 사전

이제 텍스트 상자에 "Hello"를 입력하고 "찾기" 버튼을 클릭합니다. 사전에서 "Hello"의 의미를 가져옵니다.

Python Tkinter를 사용한 단어 사전