[ruby-gnome2-doc-cvs] [Hiki] create - tut-gtk2-packing-tables-demo

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2003年 8月 24日 (日) 22:44:44 JST


-------------------------
REMOTE_ADDR = 81.51.53.240
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-gtk2-packing-tables-demo
-------------------------
= Table Packing Example

{{image_right("tablepack.png")}}

Here we make a window with three buttons in a 2x2 table. The first two buttons will be placed in the upper row. A third, quit button, is placed in the lower row, spanning both columns.

Here is the source code:

  #!/usr/bin/env ruby

  require 'gtk2'

  Gtk.init

  window = Gtk::Window.new
  window.title = "Table"
  window.signal_connect("delete_event") do
      Gtk.main_quit
      false
  end
  window.border_width = 20

  # Creates a 2x2 table.
  table = Gtk::Table.new(2, 2, true)
  window.add(table)

  [1, 2].each do |i|
      button = Gtk::Button.new("button #{i}")
      button.signal_connect("clicked") do
          puts "Hello again - button #{i} was pressed"
      end
      # Insert button 1 into the upper left quadrant of the table,
      # and button 2 into the upper right quadrant of the table.
      table.attach_defaults(button, i - 1, i, 0, 1)
  end

  button = Gtk::Button.new("Quit")
  button.signal_connect("clicked") do
      Gtk::main_quit
  end

  # Insert the quit button into the both lower quadrants of the table.
  table.attach_defaults(button, 0, 2, 1, 2)

  window.show_all
  Gtk.main





ruby-gnome2-cvs メーリングリストの案内
Back to archive index