How did I do this?
It's real easy, once you know the subcommand of Tk menus. The subcommand is "-compound left" combined with an "-image imagename" that you've already defined. When coded, it should look like this...# menuicon.tcl # --------------- # Written to show how you can use Icons with Menus, by Zipguy. # --------------- # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # create the main window menus image create photo fileopen-16 -data { R0lGODlhEAAQAIMAAPwCBASCBMyaBPzynPz6nJxmBPzunPz2nPz+nPzSBPzqnPzmnPzinPzenAAAAAAAACH5BAEAAAAALAAAAAAQABAAAARTEMhJq724hp1n8MDXeaJgYtsnDANhvkJRCcZxEEiOJDIlKLWDbtebCBaGGmwZEzCQKxxCSgQ4Gb/BbciTCBpOoFbX9X6fChYhUZYU3vB4cXTxRwAAIf5oQ3JlYXRlZCBieSBCTVBUb0dJRiBQcm8gdmVyc2lvbiAyLjUNCqkgRGV2ZWxDb3IgMTk5NywxOTk4LiBBbGwgcmlnaHRzIHJlc2VydmVkLg0KaHR0cDovL3d3dy5kZXZlbGNvci5jb20AOw== } image create photo filesave-16 -data { R0lGODlhEAAQAIQAAPwCBFRShGRmzPT6/Oz2/OTy/Nzu/NTm/AQCBMTi/Lze/Mzm/KzW/NTq/LTa/AQCxOTi5Nze3Nza3MzOzLy+xNTS1MTGxMzKzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAQABAAAAVkICCOZCkGaKqqpxAMRFEYRx0gQfvGRZ0oKZ2MdlgogC6doVc8MgJJADRQaxidU13t8HMwnlGoa4UShM2PtFp9fkAikomcQnm0IebKxGKp3/MTF3R2OVICboB7foVSZGQmkCR+IQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7 } wm title . "Menu with Icon" wm minsize . 300 0 menu .menu -tearoff 0 # add the "file" menu set m .menu.file menu $m -tearoff 0 .menu add cascade -label "File" -menu $m -underline 0 $m add command -label "New" -command "# some command" -underline 0 $m add command -label "Open" -command "# some command" -underline 0 \ -image fileopen-16 -compound left $m add command -label "Save" -command "# some command" -underline 0 \ -accelerator Ctrl+S\ -image filesave-16 -compound left $m add command -label "Exit" -underline 1 -command "exit;WriteIni;exit" . configure -menu .menu
Explanation
"image create photo fileopen-16 -data {R0lGODlh...}" defines the image,"-image fileopen-16 -compound left" combines the image with the menu item.Do you get it now? If you don't believe it (and IF you have tcl installed), you can download the code above, save it as menuicon.tcl, run it, and it should look like this:You can look at the code and get to understand what it does.