# Ruby TK GUI question

**URL:** <https://www.ruby-forum.com/t/ruby-tk-gui-question/102539>\
**Category:** Ruby\
**Created:** [February 17, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/ruby-tk-gui-question/102539 "2006-02-17T18:00:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [February 17, 2006, 6:00pm UTC](https://www.ruby-forum.com/t/ruby-tk-gui-question/102539/1 "2006-02-17T18:00:10Z")

</div>

Hi,

I am writing a Ruby GUI TK application where the top-most portion of the  
screen is a line of static menu buttons. I would like the remaining  
lower  
portion of the screen to be dynamic - as an example, one of the top  
static  
buttons is pressed, in response to that, another window appears in the  
dynamic area where someone can press more buttons, someone presses on of  
those, which then draws a data window, erasing the window which had the  
buttons, then someone closes the data window which brings the user back  
to  
the window which was drawn in response to the button press from the  
static  
button in the top portion of the screen.

Any references to Ruby TK function names would be greatly appreciated.

Thanks,

Harry

---

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [February 17, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/ruby-tk-gui-question/102539/2 "2006-02-17T19:34:35Z")

</div>

> button in the top portion of the screen.
> 
> Any references to Ruby TK function names would be greatly appreciated.
> 
> Thanks,
> 
> Harry

Are you looking for a new window that you can move around, or one  
embedded  
in your dynamic menu?

You can use TkTopLevel for a new window. If you want it embedded, there  
are a few attributes you could use with pack or grid. “before” will let  
you insert a widget before a specified widget. “after” does the  
opposite. You can use the forget method to remove it from the packing  
order when you are done.

---

<div class="post-metadata">

**Author:** ![rubyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecc23a/32.png) [@rubyman](https://www.ruby-forum.com/u/rubyman)\
**Post date:** [February 20, 2006, 10:56am UTC](https://www.ruby-forum.com/t/ruby-tk-gui-question/102539/3 "2006-02-20T10:56:50Z")

</div>

From: “Harry T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Ruby TK GUI question  
Date: Sat, 18 Feb 2006 01:57:00 +0900  
Message-ID: [200602171156918.SM03060@htruax](mailto:200602171156918.SM03060@htruax)

> I am writing a Ruby GUI TK application where the top-most portion of the  
> screen is a line of static menu buttons. I would like the remaining lower  
> portion of the screen to be dynamic - as an example, one of the top static  
> buttons is pressed, in response to that, another window appears in the  
> dynamic area where someone can press more buttons, someone presses on of  
> those, which then draws a data window, erasing the window which had the  
> buttons, then someone closes the data window which brings the user back to  
> the window which was drawn in response to the button press from the static  
> button in the top portion of the screen.

Is the one which you want like as the following?

====\< example \>====================================================  
require ‘tk’

root = Tk.root  
root.overrideredirect(true)

root.bind(‘Visibility’){root.raise} # keep on top  
root.bind(‘Configure’){  
root.geometry(“#{root.winfo\_screenwidth}x#{root.winfo\_reqheight}+0+0”)  
}

def create\_toplevel(btn)  
btn.state(:disabled)  
begin  
top = TkToplevel.new  
top.bind(‘Destroy’){btn.state(:normal)}  
top  
rescue =\> e  
top.destroy if top  
btn.state(:normal)  
fail e  
end  
end

def msg\_window(btn, msg)  
top = create\_toplevel(btn)  
TkLabel.new(top, :text=\>msg).pack(:padx=\>10, :pady=\>5)  
TkButton.new(top, :text=\>‘close’, :command=\>proc{top.destroy}).pack  
end

f = TkFrame.new.pack(:side=\>:left)

TkLabel.new(f, :text=\>’ launcher window ').pack(:side=\>:left)

TkButton.new(f, :text=\>‘foo’){|b|  
command{msg\_window(b, ‘foo’)}  
}.pack(:side=\>:left)

TkButton.new(f, :text=\>‘bar’){|b|  
command{msg\_window(b, ‘bar’)}  
}.pack(:side=\>:left)

TkButton.new(f, :text=\>‘baz’){|b|  
command{msg\_window(b, ‘baz’)}  
}.pack(:side=\>:left)

TkButton.new(:text=\>‘quit’, :command=\>proc{exit}).pack(:side=\>:right)

# Tk.mainloop
