menu, menubutton


Tcl/Tk


#!/usr/local/bin/wish4.1jp

frame .mbar -relief raised -bd 2
pack .mbar -fill x

menubutton .mbar.file -text {File} -underline 0 -menu .mbar.file.menu
menubutton .mbar.help -text {Help} -underline 0 -menu .mbar.help.menu
pack .mbar.file .mbar.help -side left -padx 1m

menu .mbar.file.menu
.mbar.file.menu add command -label "New..." -underline 0 \
		-command {puts "opening new file"}
.mbar.file.menu add command -label "Quit" -underline 0 \
		-command exit

menu .mbar.help.menu
.mbar.help.menu add command -label "About" -underline 0 \
		-command {puts "This is menu example."}

ruby/Tk


#!/usr/local/bin/ruby

require "tk"

mbar = TkFrame.new {
  relief 'raised'
  borderwidth 2
}
mbar.pack('fill' => 'x')

TkMenubutton.new(mbar) {|mb|
  text "File"
  underline 0
  menu TkMenu.new(mb) {
    add 'command', 'label' => 'New...', 'underline' => 0,
	  'command' => proc {print "opening new file\n"}
    add 'command', 'label' => 'Quit',
	  'underline' => 0, 'command' => proc{exit}
  }
  pack('side' => 'left', 'padx' => '1m')
}

TkMenubutton.new(mbar) {|mb|
  text "Help"
  underline 0
  menu TkMenu.new(mb) {
    add 'command', 'label' => 'About', 'underline' => 0,
	  'command' => proc {print "This is menu example.\n"}
  }
  pack('side' => 'left', 'padx' => '1m')
}

Tk.mainloop