tkinter 进入列表框
tkinter Entry to Listbox
我正在尝试在 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_)
我应该如何重新排列我的代码?
示例图片来自我的程序L sample picture
我觉得应该是这样的:
def input_():
label["text"] = inputword.get() #dont know what this is cuz label is undefined
listbox.insert(END, inputword.get()) #argument -> (index,string)
可以使用Listbox
的insert()
方法插入Listbox
。当您按下按钮时,这会将每个项目插入到 Listbox
的末尾。如果您希望每个项目都位于列表的顶部而不是底部,请说 0 而不是 END
。
希望你明白发生了什么,如果有任何错误或疑问,请告诉我。
干杯
我正在尝试在 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_)
我应该如何重新排列我的代码?
示例图片来自我的程序L sample picture
我觉得应该是这样的:
def input_():
label["text"] = inputword.get() #dont know what this is cuz label is undefined
listbox.insert(END, inputword.get()) #argument -> (index,string)
可以使用Listbox
的insert()
方法插入Listbox
。当您按下按钮时,这会将每个项目插入到 Listbox
的末尾。如果您希望每个项目都位于列表的顶部而不是底部,请说 0 而不是 END
。
希望你明白发生了什么,如果有任何错误或疑问,请告诉我。
干杯