我想知道如何从条目小部件中获取输入并将其添加到列表框中。提前致谢。下面的代码是一个示例GUI。
from tkinter import *
#Create a window object
#Must define window labels between window = Tk() and window.mainloop()
window = Tk()
def update_list():
list1.insert(END, e1.get())
l1 = Label(window, text= "Title")
l1.grid(row = 0, column = 0)
#Define title text
title_txt = StringVar()
e1 = Entry(window, textvariable = title_txt)
e1.grid(row = 0, column = 1)
#Define Listbox
list1 = Listbox(window, height=6, width = 35)
list1.grid(row = 2, column = 0, rowspan = 6, columnspan = 2)
b3 = Button(window, text = "Update Selected", width = 12, command= update_list())
b3.grid(row = 5, column = 3)
window.mainloop()