Ruby/TK packForget method

A

Alex DeCaria

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?
 
M

Morton Goldberg

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.

<code>
# 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
</code>

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

Regards, Morton
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top