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
?