introduction to gui programming then we clear the list box and reinsert all the data in sorted order it would be more efficient to simply insert the new bookmark in the right placebut even with hundreds of bookmarks the difference would hardly be noticeable on modern machine at the end we set the dirty flag since we now have an unsaved change def editedit(self*ignore)indexes self listbox curselection(if not indexes or len(indexes return index indexes[ name self listbox get(indexform addeditform(self parentnameself data[name]if form accepted and form nameself data[form nameform url if form name !namedel self data[nameself listbox delete( tkinter endfor name in sorted(self datakey=str lower)self listbox insert(tkinter endnameself dirty true editing is slightly more involved than adding because first we must find the bookmark the user wants to edit the curselection(method returns (possibly emptylist of index positions for all its selected items if exactly one item is selected we retrieve its text since that is the name of the bookmark the user wants to edit (and also the key to the self data dictionarywe then create new addeditform passing the name and url of the bookmark the user wants to edit after the form has been closedif the user clicked ok and set nonempty bookmark name we update the self data dictionary if the new name and the old name are the same we can just set the dirty flag and we are finished (in this case presumably the user edited the url)but if the bookmark' name has changed we delete the dictionary item whose key is the old nameclear the list boxand then repopulate the list box with the bookmarks just as we did after adding bookmark def editdelete(self*ignore)indexes self listbox curselection(if not indexes or len(indexes return index indexes[ name self listbox get(indexif tkinter messagebox askyesno("bookmarks delete""delete '{ }'?format(name))