【发布时间】:2016-03-18 02:16:21
【问题描述】:
我想使用 GUI 制作字典,我正在考虑制作两个条目,一个用于对象,另一个用于键。我想制作一个按钮来执行信息并将其添加到空字典中。
from tkinter import *
fL = {}
def commando(fL):
fL.update({x:int(y)})
root = Tk()
root.title("Spam Words")
label_1 = Label(root, text="Say a word: ", bg="#333333", fg="white")
label_2 = Label(root, text="Give it a value, 1-10:", bg="#333333", fg="white")
entry_1 = Entry(root, textvariable=x)
entry_2 = Entry(root, textvariable=y)
label_1.grid(row=1)
label_2.grid(row=3)
entry_1.grid(row=2, column=0)
entry_2.grid(row=4, column=0)
but = Button(root, text="Execute", bg="#333333", fg="white", command=commando)
but.grid(row=5, column=0)
root.mainloop()
我想稍后在我的主程序中使用该字典。你看看它是否是一个函数,我会进入 IDLE 并执行..
def forbiddenOrd():
fL = {}
uppdate = True
while uppdate:
x = input('Object')
y = input('Key')
if x == 'Klar':
break
else:
fL.update({x:int(y)})
return fL
然后在我的程序中进一步使用该功能 有什么建议? 我很感激。谢谢
【问题讨论】:
标签: python dictionary input tkinter