1#!/usr/bin/env ruby
2require 'tk'
3require 'tkextlib/iwidgets'
4
5# Create a listbox with two items (one and two)
6l = TkListbox.new(:selectmode=>:single, :exportselection=>false).pack
7l.insert('end', 'one')
8l.insert('end', 'two')
9l.selection_set(0)
10
11# Define a proc that knows how to select an item
12# from a list given an index from the tabset -command callback.
13selectItem = proc{|item|
14  l.selection_clear(l.curselection)
15  l.selection_set(item)
16  l.see(item)
17}
18
19# Create a tabset, set its -command to call selectItem
20# Add two labels to the tabset (one and two).
21ts = Tk::Iwidgets::Tabset.new(:command=>selectItem)
22ts.add(:label=>1)
23ts.add(:label=>2)
24ts.select(0)
25ts.pack(:fill=>:x, :expand=>true)
26
27# Define a proc that knows how to select a tab
28# given a y pixel coordinate from the list..
29selectTab = proc{|y| ts.select(l.nearest(y)) }
30
31# bind button 1 press to the selectTab procedure.
32l.bind('ButtonPress-1', proc{|y| selectTab.call(y) }, '%y')
33
34Tk.mainloop
35