From: "Marvin Gülker" Date: 2010-05-16T02:42:22+09:00 Subject: Re: Wx Ruby - MenuBar. What's wrong with my code? Ivo Roupa wrote: > If the Wx::MenuBar doesn't accept arguments then I will have to create a > Wx::Menu inside the MenuBar with all the items that I want. Is this > correct? I'm not sure about what you mean by that, but have a look at this minimal example (tested with Ruby 1.9): ---------------------------------------- #!/usr/bin/env ruby #Encoding: UTF-8 require "wx" class MyFrame < Wx::Frame include Wx def initialize(parent = nil) super(parent, :size => Size.new(400, 400), :title => "Test") #Just to fill that empty window StaticText.new(self, :label => "This is a test GUI.") Button.new(self, :label => "This is a test button.", :pos => Point.new(20, 20)) #1. Create the MenuBar. menu_bar = MenuBar.new #2. Create a menu you want to append to the menu bar. menu = Menu.new #3. Create menu entries. You could place submenus here to. menu.append(ID_PREFERENCES, "Preferences...") #This is a horizontal line. menu.append_separator #Yet another item menu.append(ID_EXIT, "Quit") #4. Now append the menu to the menu bar. The ampersand #sign & indicates that this menu will be accessible via #[ALT] + [F], i.e. [ALT] + []. menu_bar.append(menu, "&File") #5. Set the frame's menu bar to our newly created one. self.menu_bar = menu_bar #Process the menu bar's events. evt_menu(ID_PREFERENCES) do |event| md = MessageDialog.new(self, :caption => "Testpreferences", :message => "Your preferences dialog goes here.", :style => OK | ICON_INFORMATION) md.show_modal end evt_menu(ID_EXIT){|event| self.close} end end Wx::App.run do mainwindow = MyFrame.new mainwindow.show end ---------------------------------------- You may also have a look at bigdemo in the wxRuby samples directory (look where you install your gems to) and at the wxRuby forum at http://www.ruby-forum.com/forum/36. Marvin -- Posted via http://www.ruby-forum.com/.