image tkinter photoimage(file=imageself toolbar_images append(imagebutton tkinter button(toolbarimage=imagecommand=commandbutton grid(row= column=len(self toolbar_images- except tkinter tclerror as errprint(errtoolbar grid(row= column= columnspan= sticky=tkinter nwwe begin by creating frame in which all of the window' widgets will be contained then we create another frametoolbarto contain horizontal row of buttons that have images instead of textsto serve as toolbar buttons we lay out each toolbar button one after the other in grid that has one row and as many columns as there are buttons at the end we lay out the toolbar frame itself as the main window frame' first rowmaking it north west sticky so that it will always cling to the top left of the window (tk automatically puts the menu bar above all the widgets laid out in the window the layout is illustrated in figure with the menu bar laid out by tk shown with white backgroundand our layouts shown with gray backgrounds menubar toolbar self listbox scrollbar self statusbar figure the bookmarks program' main window layouts when an image is added to button it is added as weak referenceso once the image goes out of scope it is scheduled for garbage collection we must avoid this because we want the buttons to show their images after the initializer has finishedso we create an instance variableself toolbar_imagessimply to hold references to the images to keep them alive for the program' lifetime out of the boxtk can read only few image file formatsso we have had to use gif images if any image is not found tkinter tclerror exception is raisedso we must be careful to catch this to avoid the program terminating just because of missing image notice that we have not made all of the actions available from the menus available as toolbar buttons--this is common practice if the python imaging library' tk extension is installedall of the modern image formats become supported see www pythonware com/products/pilfor details