Tk Help needed with grid

I

Ian Hobson

Hi All,

I'm having trouble getting grid to show me something.

I am trying to write a routine (called from within initialize) that will
fill a TkPanel with a TkText or TkListbox, all linked up with two
scrollbars.

Def widgetIn(parent,type)
# return a widet of type within parent, all linked up with two
scroll bars
# and laid out with grid
widget = type.new(parent)
xscroll = TkScrollbar.new(parent,
'orient'=>'horizontal',
'command'=> proc{|*args| widget.xview
*args })
yscroll = TkScrollbar.new(parent,
'orient'=>'vertical',
'command'=> proc{|*args| widget.yview
*args })
widget.yscrollcommand(proc {|first,last| yscroll.set(first, last)})
widget.xscrollcommand(proc {|first,last| xscroll.set(first, last)})

here is where I am stuck.

now I need to grid them with 'sticky'=>'news' in layout
grid(widget, yscroll)
grid(xscroll)

and then (possibly) call gridColumnconfigure(1,'weight'=>1)
and gridRowConfigure(1,'weight=>1) to set the grid to
the right shape.

Everything I have tried has failed. What is the correct form? I'm trying
to translate from TCL and perl but I know neither language!!

Thanks

Ian
 
I

Ian Hobson

Kero said:
Yes it did thanks.

I also needed to know that the rowconfigure command is

TkGrid.rowconfigure(griddedPanel, rowNo , "weight"=>1)

and

TkGrid.columconfigure(griddedPanel, rowNo, "weight"=>1)

where griddedPanel is the parent being managed by grid.

And finally. <Blush> I had to pack a parent before I saw anything at
all!

The routine is now.

def widgetIn(parent,type)
# return a widget of type within parent,
# all linked up with two scroll bars
# and laid out with grid
# type may be TkListbox or TkText (TkCanvas not tested)
widget = type.new(parent)
widget.grid('row'=>0, 'column'=>0, 'sticky'=>'news')
yscroll = TkScrollbar.new(parent,
'orient'=>'vertical',
'command'=> proc{|*args| widget.yview
*args })
yscroll.grid('row'=>0, 'column'=>1, 'sticky'=>'ns')
xscroll = TkScrollbar.new(parent,
'orient'=>'horizontal',
'command'=> proc{|*args| widget.xview
*args })
xscroll.grid('row'=>1, 'column'=>0, 'sticky'=>'ew')
widget.yscrollcommand(proc {|first,last| yscroll.set(first,
last)})
widget.xscrollcommand(proc {|first,last| xscroll.set(first,
last)})
TkGrid.rowconfigure(parent,0,'weight'=>1)
TkGrid.columnconfigure(parent,0,'weight'=>1)
widget
end

and it works.

Regards

Ian
 
H

Hidetoshi NAGAI

Hi,

From: Ian Hobson <[email protected]>
Subject: Re: Tk Help needed with grid
Date: Sat, 6 Dec 2003 20:07:07 +0900
Message-ID: said:
I also needed to know that the rowconfigure command is
TkGrid.rowconfigure(griddedPanel, rowNo , "weight"=>1)
and
TkGrid.columconfigure(griddedPanel, rowNo, "weight"=>1)
where griddedPanel is the parent being managed by grid.

Or, griddedPanel.grid_rowconfig(rowNo , "weight"=>1)
and griddedPanel.grid_columnconfig(rowNo , "weight"=>1).
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top