我花了一些时间更新我的代码。我正在尝试创建一个返回首字母缩略词的工具。我为字母表中的每个字母创建了单独的词典,并创建了一个结果框来返回首字母缩略词的含义。但是,在运行代码时,我只能获取最新的字典来返回结果,即“c”字典中的任何首字母缩略词,并且每次添加新字典时都会失去以前的功能。我对编码很陌生,在问这个问题之前我对以前的问题做了很多研究,所以任何帮助都将不胜感激。谢谢。这是我到目前为止的代码:
from tkinter import*
acronym_dictionary={"A":"Annual", "AC":"Air Conditioning",
}
acronym_dictionary_b={"BA":"British Airway", "BB":"BumbleBee",
}
acronym_dictionary_c={"Ca":"Calcium","Co":"Company",
}
def Return_Entry(en):
content= entry.get()
result= acronym_dictionary.get(content, "Not found")
print(result)
resultBox.delete(0,END)
resultBox.insert(0,result)
def Return_EntryB(en):
content= entry.get()
result= acronym_dictionary_b.get(content, "Not found")
print(result)
resultBox.delete(0,END)
resultBox.insert(0,result)`
def Return_EntryC(en):
content= entry.get()
result= acronym_dictionary_c.get(content, "Not found")
print(result)
resultBox.delete(0,END)
resultBox.insert(0,result)
def EntryDel():
resultBox.delete(0,END)
entry.delete(0,END)
master=Tk()
master.title("The Acronym Search Engine")
master.geometry('500x400')`
Button(master, text="Clear",command=EntryDel).grid(row=7, sticky=W)`
Label(master, text="A:").grid(row=0, sticky=W)
entry=Entry()
entry.grid(row=0, column=1)
entry.bind('<Return>', Return_Entry)
Label(master, text="B:").grid(row=1, sticky=W)
entry=Entry()
entry.grid(row=1, column=1)
entry.bind('<Return>', Return_EntryB)`
Label(master, text="C:").grid(row=2, sticky=W)
entry=Entry()
entry.grid(row=2, column=1)
entry.bind('<Return>',Return_EntryC)
Label(master, text="Result:").grid( row=3,column=0 )
resultBox=Entry(master)
resultBox.grid(row=3,column=1)
mainloop()
宝慕林4294392
holdtom
相关分类