# Ruby/TK packForget method

**URL:** <https://www.ruby-forum.com/t/ruby-tk-packforget-method/87723>\
**Category:** Ruby\
**Created:** [March 5, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/ruby-tk-packforget-method/87723 "2007-03-05T16:24:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 5, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/ruby-tk-packforget-method/87723/1 "2007-03-05T16:24:45Z")

</div>

Is there a Ruby/TK equivalent to the Perl/TK packForget or gridForget  
methods, which will remove a widget from display, but doesn’t destroy  
the widget?

---

<div class="post-metadata">

**Author:** ![alexd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/96bed5/32.png) [@alexd](https://www.ruby-forum.com/u/alexd)\
**Post date:** [March 6, 2007, 5:10am UTC](https://www.ruby-forum.com/t/ruby-tk-packforget-method/87723/2 "2007-03-06T05:10:39Z")

</div>

On Mar 5, 2007, at 10:24 AM, Alex DeCaria wrote:

> Is there a Ruby/TK equivalent to the Perl/TK packForget or gridForget  
> methods, which will remove a widget from display, but doesn’t destroy  
> the widget?

The following example shows how ‘TkGrid.forget’ can cause some  
buttons to disappear.

`
# Clicking on the "four" button causes the "four" and "five" buttons to
# disappear.
require ‘tk’
DEBUG = []
begin
root = TkRoot.new {title ‘Tk Button Grid’}
```
lbls = ["one", "two", "three", "four", "five"]
btns = lbls.collect do |lbl|
   TkButton.new(root, "text"=> lbl, "command"=>lambda { Tk.bell })
end
btns[0, 3].each_with_index do |b, i|
   b.grid("row"=>0, "column"=>2*i, "columnspan"=>2)
end
btns[3, 2].each_with_index do |b, i|
   b.grid("row"=>1, "column"=>3*i, "columnspan"=>3, "sticky"=>"ew")
end
btns[3].command = lambda { TkGrid.forget(*btns[3, 2]) } # <= *******

quit_btn = TkButton.new(root) {
   text "Exit"
   command { root.destroy }
}
quit_btn.grid("row"=>2, "column"=>2, "columnspan"=>2,

```
“sticky”=>“ew”)
```
# Set window geometry.
min_w, min_h = 200, 95
root.minsize(min_w, min_h)
# Initial placement is top-center of screen.
root_x = (root.winfo_screenwidth - min_w) / 2
root.geometry("#{min_w}x#{min_h}+#{root_x}+50")

# Set resize permissions.
root.resizable(false, false)

# Make Cmnd+Q work as expected on OS X.
root.bind('Command-q') { Tk.root.destroy }

Tk.mainloop

```
ensure
puts DEBUG unless DEBUG.empty?
end
`

I imagine ‘TkPack.forget’ will work for packed widgets, but I have  
not actually tried it.

Regards, Morton
