Python: tkinter, adding entry to listbox doesn't response
Question: For some reason, it doesn't add the element to the listbox. I guess it's
because of the program order, but i'm not sure how should I properly put the
code in the right order

Here is the code:

    
    
    from tkinter import *
    
    class App(Frame):
    
        def __init__(self, parent=None):
            Frame.__init__(self, parent)
            self.parent = parent
            self.grid()
    
            self.lb = Listbox()
            self.lb.grid(column=0, row=1, columnspan=5, rowspan=4,padx=5,sticky=E+W+S+N)
    
            self.e = Entry()
            self.e.grid( column=0, row=0, padx=5)
            self.badd = Button(text="Add", command=self.addtolistbox())
            self.badd.grid( column=1, row=0, padx=5, pady=5)
            self.brmv = Button(text="Remove")
            self.brmv.grid(column=2, row=0, padx=5, pady=5)
    
        def addtolistbox(self):
            self.lb.insert(0, self.e.get())
    
    
    App = App(Tk())
    App.mainloop()
    


Answer: Change this line

    
    
    self.badd = Button(text="Add", command=self.addtolistbox())
    

to this

    
    
    self.badd = Button(text="Add", command=self.addtolistbox)
    

The problem is that instead of binding the callback function to the button,
you _execute_ the function once (adding an empty string to the list) and then
bind the result of the function call to the button, i.e. `None`.

