# Trying to get back into Tk

**URL:** <https://www.ruby-forum.com/t/trying-to-get-back-into-tk/154678>\
**Category:** Ruby\
**Created:** [December 2, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/trying-to-get-back-into-tk/154678 "2008-12-02T21:50:14Z")\
**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, 9:50pm UTC](https://www.ruby-forum.com/t/trying-to-get-back-into-tk/154678/1 "2008-12-02T21:50:14Z")

</div>

After a hiatus of many years, I’m trying to get back into Tk via Ruby.  
Unfortunately, my first attempt–a simple text box with attached  
scroll bar–doesn’t work very well. The scroll bar doesn’t show up,  
and the text box only gets so large; past that point, enlarging the  
window doesn’t enlarge the text box. I’ve copied in my code, and would  
greatly appreciate it if someone could tell me where I’m going wrong.  
It’s been a long time since using Tk, and I’ve never used it with Ruby.

Thanks,  
Ken

require ‘tk’

ROOT = TkRoot.new {title ‘WIN’}  
FRAME = TkFrame.new(ROOT)

TEXT = TkText.new(FRAME) {  
pack ‘side’ =\> ‘left’, ‘fill’ =\> ‘both’, ‘expand’ =\> ‘true’  
}  
YSCROLL = TkScrollbar.new(FRAME) do command {  
|first, last| TEXT.yview first, last  
pack ‘side’ =\> ‘right’, ‘fill’ =\> ‘y’  
}  
end  
TEXT.yscrollcommand {|first, last| YSCROLL.set(first, last) }  
FRAME.pack  
Tk.mainloop

---

<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:05am UTC](https://www.ruby-forum.com/t/trying-to-get-back-into-tk/154678/2 "2008-12-03T00:05:35Z")

</div>

From: Kenneth McDonald [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Trying to get back into Tk  
Date: Wed, 3 Dec 2008 05:42:41 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> YSCROLL = TkScrollbar.new(FRAME) do command {  
> |first, last| TEXT.yview first, last  
> pack ‘side’ =\> ‘right’, ‘fill’ =\> ‘y’  
> ^^^ Here is the reason of your trouble.  
> }  
> end

The ‘pack’ method call is written in the callback of the scrollbar.  
You have to write it at external of the callback.  
For example,
