首页 > 解决方案 > 输入用户获取字典python

问题描述

我正在尝试创建一个条目小部件,我可以在其中放置字典编号,所以在这种情况下,我有数字 1 和 2。

如果我在条目小部件中输入数字 1,它将打印该数字。我要做的是输入一个数字并获取相应的不起作用的键值对。如果我输入 IDLE info[1] 它正在工作,但是当我尝试通过该功能时它不起作用。我收到错误 KeyError。

Interface = Tk()
Interface.title("H")

info = {1: {"url":"https://..."},2: {"url":"https://..."}}


def dictklik():
    p = VulIn.get()
    print(p)
## not working print(info[p])

w = Button(Interface, text="Press", command=dictklik)
w.place(x=80,y =15)



Label(Interface,text="Typ the number").pack()

searchD = IntVar()
VulIn = Entry(Interface, textvariable=searchD)
VulIn.pack()





Interface.geometry("500x500")
Interface.mainloop()

标签: pythontkinter

解决方案


推荐阅读