使用条目查找字典

时间:2015-12-25 19:16:37

标签: python python-2.7 dictionary tkinter

我正在尝试使用entry.get()方法来使用输入来搜索字典 我在一个文件中有很少的字典,字典的名称是一本书的标题,我试图用年份制作一个标签,但它不会使用它,因为它是一个字符串。
这是GUI:

from Tkinter import *
from Fonction import *  #Fonction is where my functions are stored
from alexandria import * #alexandria is where my dicts are

root2 = Tk()
root2.title("Find")

Title = Label(root2, text = 'Book Title',  font = ('arial',20,'bold'))
Title.grid (row = 0, column = 0)
titlein = Entry(root2)
titlein.grid (row = 0, column = 1)
Findbutt = Button (root2, text = 'Find', font = ('arial',20,'bold'), command = 
lambda : search(titlein.get())) #titlein.get is a string and returns an error
Findbutt.grid(row = 1, columnspan = 2)    

root2.mainloop()        

#Here is the funtion i am trying to use:
def search(title):
    y = title.get("Year")
    fame = Label (root, text = "Year")
    fame.grid(root,row = 3, column = 0)
    foo = Label (root, text = y)
    foo.grid(root, row = 3, column = 1)

0 个答案:

没有答案