0

I am trying to make a program which searches for common acronyms which are used in work. I am a beginner to using computer programming and this is my first project. I thought I could use a dictionary of acronyms and then be able to use the entry box to search for the key which would return the associated value for example a search for AKA would return 'Also Known As'

This is my progress so far (Any pointers would be much appreciated):

from tkinter import*

master=Tk()    
master.title("The Acronym Search Engine")
master.geometry('300x100')

def return_entry(en):
    content=entry.get()
    print(content)

acronym_dictionary={"AKA":"Also known as", "OT":"Overtime"}

Label(master, text="Search box:").grid(row=0, sticky=W)

entry=Entry(master)    
entry.grid(row=0, column=1)
entry.bind('<Return>', return_entry)

mainloop()
krlzlx
  • 5,752
  • 14
  • 47
  • 55
Emily
  • 5
  • 4
  • 6
    Please indent the code properly –  May 30 '18 at 13:46
  • You need to think about what you mean with "return". Where do you want `Also known as` to be returned? In the console? In a tkinter Label? In a popup box? Without that info (and some effort by you to try and implement this) I'm afraid your question is too broad. – fhdrsdg May 30 '18 at 13:56
  • Hi @fhdrsdg I am ideally looking to return the information in a label.is it possible to do something like: if return_entry = AKA print("Also known as"). Sorry if this is a seems a silly question (very new to python) – Emily May 30 '18 at 14:04
  • 1
    Of course this is possible, and information on how to do this is abundant on stack overflow. See [this](https://stackoverflow.com/a/17126015/3714930), [this](https://stackoverflow.com/a/34901558/3714930) and many more questions. – fhdrsdg May 30 '18 at 14:15

1 Answers1

0

Does this work for you?

I've used the dictionaries get method which allows a default to be returned if the acronym cannot be found. Return is placed in to a new entry field called resultsBox once the enter key is pressed inside the first entry field.

from tkinter import*

acronym_dictionary={"AKA":"Also known as", "OT":"Overtime"}

def return_entry(en):
    content=entry.get()
    result = acronym_dictionary.get(content,"Not Found")
    print(result)
    resultBox.delete(0,END)
    resultBox.insert(0,result)

master=Tk()
master.title("The Acronym Search Engine")
master.geometry('300x100')

Label(master, text="Search box:").grid(row=0, sticky=W)
entry=Entry(master)
entry.grid(row=0, column=1)
entry.bind('<Return>', return_entry)
Label(master, text="Result:").grid(row=1,column=0)
resultBox=Entry(master)
resultBox.grid(row=1,column=1)
mainloop()
scotty3785
  • 6,763
  • 1
  • 25
  • 35