Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用条目查找字典_Python_Python 2.7_Dictionary_Tkinter - Fatal编程技术网

Python 使用条目查找字典

Python 使用条目查找字典,python,python-2.7,dictionary,tkinter,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 =

我正在尝试使用
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)

你能解释一下你想用代码y=title.get(“年份”)做什么吗?拿出你的字典。可能您需要一本包含所有书籍的字典,以及类似的
一本包含所有书籍[title]的字典。获取('Year')
我正在尝试从条目中输入的字典中获取年份。您得到的确切错误消息是什么?你能把
print(title)
作为
search
函数的第一行,并向我们显示输出吗?
titlein.get()
返回一个
str
你正在做的
title.get(“年”)
你是否把
title
误认为是
dict