# Dynamic menu odd display behaviour

**URL:** <https://www.ruby-forum.com/t/dynamic-menu-odd-display-behaviour/116305>\
**Category:** Ruby-Gnome 2\
**Created:** [October 4, 2007, 11:41am UTC](https://www.ruby-forum.com/t/dynamic-menu-odd-display-behaviour/116305 "2007-10-04T11:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [October 4, 2007, 11:41am UTC](https://www.ruby-forum.com/t/dynamic-menu-odd-display-behaviour/116305/1 "2007-10-04T11:41:02Z")

</div>

Hi,

I want to add menu items dynamically to a menu when it is activated.  
The following code almost works. But the first time you hit the  
the File menu button, it looks like the area for the menu is drawn, but  
the items do not appear on it. Subsequent presses work correctly, but  
the first  
lot of items added always appear blank in the menu.

Any ideas on where I’ve gone wrong?

This is on windows, gtk 2.0.11 rubygnome 2-0.16.

Thanks in advance,  
Martin

require ‘gtk2’  
Gtk.init  
win = Gtk::Window.new

menu = Gtk::MenuBar.new  
file\_menu = Gtk::MenuItem.new(“File”)  
file\_sub\_menu = Gtk::Menu.new  
file\_menu.set\_submenu( file\_sub\_menu )

file\_menu.signal\_connect(“select”){  
%w( cut copy paste).each{|name|  
item = Gtk::MenuItem.new( name )  
file\_sub\_menu.append( item )  
item.show\_all  
}  
}

menu.append( file\_menu )  
menu.show\_all

vbox = Gtk::VBox.new(false)  
vbox.pack\_start( menu , false ,true , 0 )  
win.add( vbox )  
win.show\_all  
Gtk.main

---

<div class="post-metadata">

**Author:** ![dhstudio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@dhstudio](https://www.ruby-forum.com/u/dhstudio)\
**Post date:** [October 4, 2007, 12:52pm UTC](https://www.ruby-forum.com/t/dynamic-menu-odd-display-behaviour/116305/2 "2007-10-04T12:52:01Z")

</div>

Hi Martin,

> But the first time you hit the the File menu button, it looks like the area for \> the menu is drawn, but the items do not appear on it.

That works for me. When I click the first time on “File” I see the three  
menu items.

I’m using gtk version 2.10.11-ubuntu3 and ruby-gtk 0.16. Maybe this is a  
windows related gtk bug?
