More tk stuff

OK, I dug up an answer to my previous question; here's code to implement a window with scrollbars:

require 'tk'

root = TkRoot.new() { title "(Sc)rolling, (sc)rolling), (sc)rolling..." }
xbar = TkScrollbar.new(root, 'orient'=>'h').pack('side'=>'bottom', 'fill'=>'x')
ybar = TkScrollbar.new(root, 'orient'=>'v').pack('side'=>'right', 'fill'=>'y')
text = TkText.new(root, 'wrap'=>'none', 'width'=>20).pack('fill'=>'both', 'expand'=>true)
text.insert('end', "A string that is longer than fits on one line...")
xbar.command(proc {|*args| text.xview(*args)})
text.xscrollcommand(proc {|first, last| xbar.set(first, last)})
ybar.command(proc {|*args| text.yview(*args)})
text.yscrollcommand(proc {|first, last| ybar.set(first, last)})

Tk.mainloop

Next question; how does one access the new 'themed' widgets in the modern releases of Tk? Something like ttk::entry, I mean; I assume the double colon wouldn't be used in Ruby (and I certainly couldn't get it to work.)

Thanks,
Ken

Message-ID: <09DB2CED-6766-47E4-AF0C-55253E4C425C@sbcglobal.net>

OK, I dug up an answer to my previous question; here's code to
implement a window with scrollbars:

Ruby/Tk supports a more simple way to combine a scrollbar and
its target widget.
The following part of your script

ยทยทยท

From: Kenneth McDonald <kenneth.m.mcdonald@sbcglobal.net>
Subject: More tk stuff
Date: Wed, 3 Dec 2008 06:19:04 +0900
---------------------------------------------------------

xbar = TkScrollbar.new(root, 'orient'=>'h').pack('side'=>'bottom',
'fill'=>'x')
ybar = TkScrollbar.new(root, 'orient'=>'v').pack('side'=>'right',
'fill'=>'y')
text = TkText.new(root, 'wrap'=>'none',
'width'=>20).pack('fill'=>'both', 'expand'=>true)
text.insert('end', "A string that is longer than fits on one line...")
xbar.command(proc {|*args| text.xview(*args)})
text.xscrollcommand(proc {|first, last| xbar.set(first, last)})
ybar.command(proc {|*args| text.yview(*args)})
text.yscrollcommand(proc {|first, last| ybar.set(first, last)})

---------------------------------------------------------
can rewrite to the following.
---------------------------------------------------------
text = TkText.new(root, :wrap=>'none', :width=>20).pack(:fill=>'both', :expand=>true)
text.insert(:end, "A string that is longer than fits on one line...")
xbar = text.xscrollbar(TkScrollbar.new(root).pack(:side=>'bottom', :fill=>'x'))
ybar = text.yscrollbar(TkScrollbar.new(root).pack(:side=>'right', :fill=>'y'))
---------------------------------------------------------

Next question; how does one access the new 'themed' widgets in the
modern releases of Tk? Something like ttk::entry, I mean; I assume the
double colon wouldn't be used in Ruby (and I certainly couldn't get it
to work.)

Please require 'tkextlib/tile', and you can use Tk::Ttk::Entry and so on.
The latest version of Ruby/Tk (e.g. Ruby 1.8.7) includes
a sample script 'ttk_wrapper.rb' at 'ext/tk/sample' directory
to use Ttk widgets as default.
For example, if you call "ruby ttk_wrapper.rb your_rubytk_script.rb",
widget classes on 'your_rubytk_script.rb' (e.g. TkEntry) means
the ones on Tk::Ttk widgets (e.g. Tk::Ttk::Entry).
It uses 'Tk.default_widget_set=' method.
When call "Tk.default_widget_set = :Ttk", standard widget class names
denote the ones of ttk widgets.
Then, if you want to use original entry widgets of Tk,
Tk::Entry denotes the original one.
You can switch the default to original by "Tk.default_widget_set = :Tk",
whenever you want.
--
Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)