require 'tk' fbar = TkFrame.new.pack('fill'=>'x') scr = TkScrollbar.new.pack('fill'=>'y', 'side'=>'right') text = TkText.new.pack('side'=>'right') text.yscrollbar( scr ) cut_buffer = '' def open_file ( text ) filename = Tk.getOpenFile file = open( filename ) textdata = file.read file.close text.insert( 'end', textdata ) end def save_file ( text ) filename = Tk.getSaveFile textdata = text.get( '1.0','end' ) file = open( filename, "w" ) file.print( textdata ) file.close end menu_spec = [ [ ['File', 0], ['Open File', proc{open_file text}], ['Save File', proc{save_file text}], '---', ['Clear', proc{ text.delete('1.0', 'end') }], '---', ['Quit', proc{exit}] ], [ ['Edit', 0], ['Cut', proc{ cut_buffer = text.get('sel.first', 'sel.last'); text.delete('sel.first', 'sel.last') }], ['Copy', proc{ cut_buffer = text.get('sel.first', 'sel.last') }], ['Paste', proc{ text.insert('insert',cut_buffer ) }] ] ] TkMenubar.new(fbar, menu_spec, 'tearoff'=>false).pack('fill'=>'x', 'side'=>'top') Tk.mainloop