python - 输入用户获取字典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()
解决方案
推荐阅读
- android - 让我的 Activty 在通知点击时保持打开状态?
- visual-studio - nuget packages 文件夹是在解决方案级别和项目级别提示路径中创建的,无法找到它
- python - 在 python dict 中打印键值时出错:字符串索引必须是整数
- django - 如何在 Django 中连接多个数据库?
- c - 带有 pcap 分段错误的数据包嗅探
- javascript - 发送多部分表单数据请求
- c# - 当我尝试添加新的迁移时,我得到了这个异常
- reactjs - 反应功能组件未初始化
- c# - 存储库定义的比较
- mysql - 无法在 Plesk 服务器上创建或删除数据库