I'm working on learning GUI development, I'm attempting to utilize the GUI for a user to search the dictionary: my code so far is
from tkinter import *
class Interface(Frame):
def __init__(self, master):
super(Interface, self).__init__(master)
self.grid()
self.create_widget()
def create_widget(self):
self.pwrd= Label(self, text='Address Book')
self.pwrd.grid(row=0, column=2)
self.searchlbl= Label(self, text='Enter Search Query:')
self.searchlbl.grid(row=2, column=0)
self.search= Entry(self)
self.search.grid(row=2,column=1,columnspan=1)
self.subsearch= Button(self, text='Submit', command=self.searchfor)
self.subsearch.grid(row=2,column=2)
self.searchresult= Text(self, width=40, height=10, wrap=WORD)
self.searchresult.grid(row=3,column=0, columnspan=2, rowspan=2)
def searchfor(self):
query=str(self.search)
self.searchresult.delete(0.0,END)
if query in ab.book:
result=ab.book[str(query)]
self.searchresult.insert(0.0,result)
else:
result='Query not found.'
self.searchresult.insert(0.0,result)
class AddressBook(object):
"""AddressBook Features"""
def __init__(self, book):
self.book=book
def search(self,query):
query=query.lower()
if query in self.book:
return self.book[query]
if __name__=='__main__':
ab={'josh':'me'}
ab=AddressBook(ab)
root=Tk()
root.title('Address Book')
root.geometry('1500x800')
Interface(root)
root.mainloop()
regardless of the user input the Text displays 'Query not found', upon further examination I found that self.book became {{'josh':'me'}} why did it double the dictionary and is that why the search is being messed up?