我正在尝试在 Python 3.8 上制作一个待办事项列表程序。它将在以下方面获取用户的输入def input_():
label["text"] = inputword.get()
inputword=Entry()
inputword.pack(anchor = "nw", padx = 10, pady = 10)和一个按钮:add_input= Button(text ="Add to List",
command = input_,
bg = "#ae0000",
fg= "white",
font=("Calibri", "15", "bold")
)
add_input.pack(anchor="nw", padx=10)这有效,但我无法将我的输入添加到列表中。listbox=Listbox()
listbox.place(x=250,y=250)
listbox.insert(0, add_input or maybe input_)我应该如何重新排列我的代码?
1 回答

繁华开满天机
TA贡献1816条经验 获得超4个赞
我认为应该是这样的:
def input_(): label["text"] = inputword.get() #dont know what this is cuz label is undefined listbox.insert(END, inputword.get()) #argument -> (index,string)
您可以使用insert()
的方法Listbox
插入到Listbox
. Listbox
当您按下按钮时,这会将每个项目插入到 的末尾。如果您希望每个项目位于列表的顶部而不是底部,请说 0 而不是END
。
希望您明白发生了什么,如果有任何错误或疑问,请告诉我。
添加回答
举报
0/150
提交
取消