Take the 2-minute tour ×

I have got some customers, e.g. customer1. And I have stored their data in a dictionary like this:

customer1 = {"Age": 20, "Gender": "Male",}

I want to have a Tkinter entry box and a text variable called searchterm:

searchterm = StringVar()
entry = Entry(frame, textvariable=searchterm)

Then I want to be able to find the dictionary using the value typed in and then display the data in a text widget.

I'm new to python so please help.

share|improve this question
Don't use per-customer variables. Use a dictionary instead; customers = {} then customers['customer1'] = {...}. –  Martijn Pieters May 4 '13 at 17:23
add comment

1 Answer

Assuming you have a frame called frame1

#Create Text to present result and Entry for input

text1 = Text(frame1,bg="white",width=60)
entry1 = Entry(frame1,bg="yellow")

#The handler necessary to process input

def handler1(event):
        #What ever you want to do with data#
        #get result...#

#A button to engage your function with input

share|improve this answer
I'm sorry, I don't think I explained it properly. This is the code I have already: from tkinter import * root = Tk() frame = Frame() word1 = StringVar() customer1 = {'Lawn_Area': '20 m2', 'Lawn_Cost': '£30',} entry = Entry(frame, textvariable=word1) entry.pack() text = Text(frame, width=40, height=10) text.pack() diction = word1.get() text.insert('1.0', diction.items()) root.mainloop() –  user2350306 May 4 '13 at 18:24
What is the format of your dictionary with all the customers? Or where are your customers data? In a file? –  Georgios May 4 '13 at 18:27
Sorry I do not quite get what you mean? –  user2350306 May 4 '13 at 18:27
First of all, you do not call the dictionary properly. –  Georgios May 4 '13 at 18:50
It is difficult to read your code properly but as I see you never make a call to the customers dictionary...you write text.insert('1.0', diction.items()) but diction is a string that is your input not a dictionary, that is why you should probably get an Error. THe way I see it you must use diction to make a call from a collection of customers...meaning what Martijn Pieters mentioned above...for example text.insert('1.0', customers[diction]) where customers = {customer1, customer2, ...} –  Georgios May 4 '13 at 18:58
show 2 more comments

Your Answer


