0

I was wondering how you take input from the entry widget and add it to the listbox. Thanks in advance. The code below is a sample 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()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Jay
  • 23
  • 2
  • the command parameter takes a function, but you don't have to call it, the button event will trigger it itself – PRMoureu Nov 12 '17 at 00:58
  • One must not call the button command in the button definition. This is a duplicate of a common mistake. You should have carefully looked at, and posted, the error and traceback displayed when clicking the button. – Terry Jan Reedy Nov 12 '17 at 01:05
  • I did remove the () in the command parameters and that did not work. – Jay Nov 12 '17 at 01:10
  • I got it to work thanks! – Jay Nov 12 '17 at 01:15

0 Answers0