From: Hidetoshi NAGAI Date: 2008-02-06T03:55:09+09:00 Subject: Re: Ruby/Tk/Iwidgets tabnotebook (and scrollbar) Probably the following is better. Sorry. > #!/usr/bin/env ruby > require 'tk' > require 'tkextlib/iwidgets' > > # Create the tabnotebook widget and pack it. > tn = Tk::Iwidgets::Tabnotebook.new(:width=>300, :height=>100) > tn.pack(:anchor=>:nw, :fill=>:both, :expand=>true, > :side=>:top, :padx=>10, :pady=>0) > > # Add twenty pages to the tabnotebook > 1.upto(20) { |t| > txt = 'Page ' + t.to_s > tn.add(:label => txt) > } # Command to control the tabset class Tk::Iwidgets::Tabnotebook def show_tab(idx) if (prev = @tabset.index(idx) - 1) < 0 @tabset.start = 0 return end case cget(:tabpos) when 's', 'n' poskey = :left szkey = :width when 'e', 'w' poskey = :top szkey = :height end if (hd = @tabset.tabcget(idx, poskey)) < 0 @tabset.start -= hd elsif hd + (sz = @tabset.tabcget(idx, szkey)) > (tabs_sz = @tabset[szkey]) @tabset.start -= hd - tabs_sz + 2*(hd - @tabset.tabcget(prev, poskey)) - sz + 1 end end end tn.component_widget('tabset').command{|idx| tn.view(idx) tn.show_tab(idx) } > button = TkButton.new(tn.child_site(0),:text =>'Go to Page 20').pack > button.command { > tn.select(19) # tn.view etc have the same problem > } > > # Select the first page of the tabnotebook. > tn.select(0) > > # Create the scrollbar > # and the notebook together, then pack the scrollbar > tn.xscrollbar(TkScrollbar.new).pack(:fill=>:x, > :expand=>true, :padx=>10) > > Tk.mainloop -- Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)