From: Mohammad — [email protected]
Subject: Tk Layout help please
Date: Mon, 23 Oct 2006 03:39:41 +0900
Message-ID: [email protected]
okay this is an example of what I want it to look like:
Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos
How about this?
require ‘tk’
class Editable_TkListbox < TkListbox
def _ebox_placer(coord_y)
idx = self.nearest(coord_y)
x, y, w, h = self.bbox(idx)
@ebox.place(:x => 0, :relwidth => 1.0,
:y => y - self.selectborderwidth,
:height => h + 2 * self.selectborderwidth)
@ebox.pos = idx
@ebox.value = self.listvariable.list[idx]
@ebox.focus
end
private :_ebox_placer
def initialize(*args)
super(*args)
unless self.listvariable
self.listvariable = TkVariable.new(self.get(0, :end))
end
@ebox = TkEntry.new(self){
@pos = -1
def self.pos; @pos; end
def self.pos=(idx); @pos = idx; end
}
@ebox.bind('Return'){
list = self.listvariable.list
list[@ebox.pos] = @ebox.value
self.listvariable.value = list
@ebox.place_forget
@ebox.pos = -1
}
@ebox.bind('Escape'){
@ebox.place_forget
@ebox.pos = -1
}
self.bind('Double-1', '%y'){|y| _ebox_placer(y) }
end
end
if $0 == FILE
scr = TkScrollbar.new.pack(:side=>:right, :fill=>:y)
lbox1 = Editable_TkListbox.new.pack(:side=>:left)
lbox2 = Editable_TkListbox.new.pack(:side=>:left)
scr.assign(lbox1, lbox2)
lbox1.insert(:end, *%w(a b c d e f g h i j k l m n))
lbox2.insert(:end, 0,1,2,3,4,5,6,7,8,9,0,1,2,3)
Tk.mainloop
end