TkScrollbox with horizontal scrollbar

E

Enrico Schwass

Hello

I recently found this very useful widget TkScrollbar. It works great, if
you need a listbox with vertical scrollbar.
What I am missing is some more documentation. What, if i need a
horizontal bar or in my case both?

I think there is an easy way to achieve this. Some parameters I miss??

Thanks in advance
Enno
 
H

Hidetoshi NAGAI

From: Enrico Schwass <[email protected]>
Subject: TkScrollbox with horizontal scrollbar
Date: Mon, 6 Jun 2005 15:59:06 +0900
Message-ID: said:
I recently found this very useful widget TkScrollbar. It works great, if
you need a listbox with vertical scrollbar.
What I am missing is some more documentation. What, if i need a
horizontal bar or in my case both?

Here you are. Please see "<ruby-src>/ext/tk/sample/tktextframe.rb" also.
----------------------------------------------------
#
require 'tk'

class TkXYScrollbox<TkListbox
include TkComposite
def initialize_composite(keys=nil)
list = TkListbox.new(@frame)

xscr = TkScrollbar.new(@frame)
yscr = TkScrollbar.new(@frame)

@path = list.path

list.xscrollbar(xscr)
list.yscrollbar(yscr)

TkGrid.rowconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)
TkGrid.columnconfigure(@frame, 0, 'weight'=>1, 'minsize'=>0)

list.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
xscr.grid('row'=>1, 'column'=>0, 'sticky'=>'ew')
yscr.grid('row'=>0, 'column'=>1, 'sticky'=>'ns')

delegate('DEFAULT', list)
delegate('foreground', list)
delegate('background', list, xscr, yscr)
delegate('borderwidth', @frame)
delegate('relief', @frame)

configure keys if keys
end
private :initialize_composite
end

################################################
# test
################################################
if __FILE__ == $0
lst = TkXYScrollbox.new:)height=>7).pack
('A'..'Z').each_with_index{|s, n| lst.insert:)end, s*(n+1))}
Tk.mainloop
end
----------------------------------------------------

Of course, you can use a TkScrollbox with a horizontal scrollbar.
However, probably you'll have some trouble on layouting them.
It is better to define a new class which use grid geometry manager
instead of pack geometry manager.
 

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top