Trying to get back into Tk

  • Thread starter Kenneth McDonald
  • Start date
K

Kenneth McDonald

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
 
H

Hidetoshi NAGAI

From: Kenneth McDonald <[email protected]>
Subject: Trying to get back into Tk
Date: Wed, 3 Dec 2008 05:42:41 +0900
Message-ID: said:
YSCROLL = TkScrollbar.new(FRAME) do command {
|first, last| TEXT.yview first, last
pack 'side' => 'right', 'fill' => 'y'
^^^ Here is the reason of your trouble.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top