使用条目查找词典

2024-10-01 09:16:01 发布

您现在位置:Python中文网/ 问答频道 /正文

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

Tags: textfromimportgettitleiscolumnroot