except (environmenterrorpickle pickleerroras errtkinter messagebox showwarning("bookmarks error""failed to load { }:\ { }formatself filenameerr)parent=self parentwhen this method is called we know that any unsaved changes have been saved or abandonedso we are free to clear the list box we set the current filename to the one passed inclear the list box and the dirty flagand then attempt to open the file and unpickle it into the self data dictionary once we have the data we iterate over all the bookmark names and append each one to the list box finallywe give an informative message in the status bar and update the window' title bar if we could not read the file or if we couldn' unpickle itwe pop up warning message box to inform the user def filequit(selfevent=none)if self okaytocontinue()self parent destroy(this is the last file menu option method we give the user the chance to save any unsaved changesif they cancel we do nothing and the program continuesotherwisewe tell the parent to destroy itself and this leads to clean program termination if we wanted to save user preferences we would do so herejust before the destroy(call def editadd(self*ignore)form addeditform(self parentif form accepted and form nameself data[form nameform url self listbox delete( tkinter endfor name in sorted(self datakey=str lower)self listbox insert(tkinter endnameself dirty true if the user asks to add new bookmark (by clicking edit-addor by clicking the toolbar buttonor by pressing the ctrl+ keyboard shortcut)this method is called the addeditform is custom dialog covered in the next subsectionall that we need to know to use it is that it has an accepted flag which is set to true if the user clicked okand to false if they clicked canceland two data attributesname and urlthat hold the name and url of the bookmark the user has added or edited we create new addeditform which immediately pops up as modal dialog--and therefore blocksso the if form accepted statement is not executed until the dialog has closed if the user clicked ok in the addeditform dialog and they gave the bookmark namewe add the new bookmark' name and url to the self data dictionary