HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.2.10/ext/tk/sample/tkextlib/iwidgets/sample/tabset.rb
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/iwidgets'

# Create a listbox with two items (one and two)
l = TkListbox.new(:selectmode=>:single, :exportselection=>false).pack
l.insert('end', 'one')
l.insert('end', 'two')
l.selection_set(0)

# Define a proc that knows how to select an item
# from a list given an index from the tabset -command callback.
selectItem = proc{|item|
  l.selection_clear(l.curselection)
  l.selection_set(item)
  l.see(item)
}

# Create a tabset, set its -command to call selectItem
# Add two labels to the tabset (one and two).
ts = Tk::Iwidgets::Tabset.new(:command=>selectItem)
ts.add(:label=>1)
ts.add(:label=>2)
ts.select(0)
ts.pack(:fill=>:x, :expand=>true)

# Define a proc that knows how to select a tab
# given a y pixel coordinate from the list..
selectTab = proc{|y| ts.select(l.nearest(y)) }

# bind button 1 press to the selectTab procedure.
l.bind('ButtonPress-1', proc{|y| selectTab.call(y) }, '%y')

Tk.mainloop