Exercise

If you haven't noticed it already, the program has a bug. When the list box is empty and the user clicks it, an IndexErroris generated in the terminal:

Why that happens?

That happens because when the user clicks the list box this code is executed:

list1.bind('<<ListboxSelect>>',get_selected_row)

That line calls theget_selected_row function:

def get_selected_row(event):
    global selected_tuple
    index=list1.curselection()[0]
    selected_tuple=list1.get(index)
    e1.delete(0,END)
    e1.insert(END,selected_tuple[1])
    e2.delete(0,END)
    e2.insert(END,selected_tuple[2])
    e3.delete(0,END)
    e3.insert(END,selected_tuple[3])
    e4.delete(0,END)
    e4.insert(END,selected_tuple[4])

Since the listbox is empty, then list1.curselection()will be an empty list with no items. Trying to access the first item of that list with [0] in line 3 will throw an error since there is no first item in the list.

Please try to fix that bug. The next lecture contains the solution.