From: Bart Masschelein Date: 2005-08-30T04:00:31+09:00 Subject: Re: Tk menu I love this list!! The response time is almost like asking your next-cubicle colleague! Anyway, if sbdy is still dazzled by how to do submenu-ing, here is an example, using the previous reply: menu_spec_2 = [ [ ['main 1', 0], ['1 sub', 0] ], [ ['main 2', 0], ['2 sub 1', [ ['2 sub sub 1', 0], ['2 sub sub 2', 0] ] ], ['2 sub 2', 0] ] ] Thanks! gr.b. Joe Van Dyk wrote: >On 8/29/05, Bart Masschelein wrote: > > >>Hello there, >> >>I started experimenting with Tk, out of the box, with the basic >>examples, and I loved the way to implement menus: >> >>menu_spec_1 = >>[ [ ['main 1', 0], >> ['1 sub', 0] >> ], >> [ ['main 2', 0], >> ['2 sub', 0] >> ] >>] >> >>and then calling >> >>TkMenubar.new(root, menu_spec_2, 'tearoff'=>false).pack('fill'=>'x', >>'side'=>'top') >> >>However, I wanted to have a submenu under a menu item, so I tried >> >>menu_spec_2 = >>[ [ ['main 1', 0], >> ['1 sub', 0] >> ], >> [ ['main 2', 0], >> [ ['2 sub', 0], >> ['2 sub sub', 0] >> ] >> ] >>] >> >>This doesn't work, Ruby gives me an error. So apparently this is not >>supported. Has sbdy already extended the menuspec.rb file to support >>this behaviour, or would this straightforward to do, or even feasible >>(I'm just starting with Ruby)? >> >>I want to avoid the 'hassle' of creating each menu item itself, and then >>structuring them. Been there, done that, in other languages. >> >> > >Yeah, the menu spec thing is sorta confusing for submenus. From the >TkMenuSpec docs (found at http://www.ruby-doc.org): > >The format of the menu_spec is: > > [ menu_info, menu_info, ... ] > >And the format of the menu_info is: > > [ > [text, underline, configs], # menu button/entry (*1) > [label, command, underline, accelerator, configs], # command entry > [label, TkVar_obj, underline, accelerator, configs], # checkbutton entry > [label, [TkVar_obj, value], > underline, accelerator, configs], # radiobutton entry > [label, [[...menu_info...], [...menu_info...], ...], > underline, accelerator, configs], # cascade entry > '---', # separator > ... > ] > >underline, accelerator, and configs are optional pearameters. Hashes >are OK instead of Arrays. Then the entry type ('command', >'checkbutton', 'radiobutton' or 'cascade') is given by 'type' key >(e.g. :type=>'cascade'). When type is 'cascade', an array of menu_info >is acceptable for 'menu' key (then, create sub-menu). > > > > > > >