# More tk stuff

**URL:** <https://www.ruby-forum.com/t/more-tk-stuff/154683>\
**Category:** Ruby\
**Created:** [December 2, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/more-tk-stuff/154683 "2008-12-02T22:25:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [December 2, 2008, 10:25pm UTC](https://www.ruby-forum.com/t/more-tk-stuff/154683/1 "2008-12-02T22:25:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kenneth\_McDonald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/dc4da7/32.png) [@Kenneth\_McDonald](https://www.ruby-forum.com/u/Kenneth_McDonald)\
**Post date:** [December 3, 2008, 12:04am UTC](https://www.ruby-forum.com/t/more-tk-stuff/154683/2 "2008-12-03T00:04:25Z")

</div>

From: Kenneth McDonald [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: More tk stuff  
Date: Wed, 3 Dec 2008 06:19:04 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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

> 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.
