# Ruby/TK Question

**URL:** <https://rubytalk.org/t/ruby-tk-question/14637>\
**Category:** ruby-talk\
**Created:** [5 November 2004 18:22 UTC](https://rubytalk.org/t/ruby-tk-question/14637 "2004-11-05T18:22:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kujawa\_Greg](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@Kujawa\_Greg](https://rubytalk.org/u/Kujawa_Greg)\
**Post date:** [5 November 2004 18:22 UTC](https://rubytalk.org/t/ruby-tk-question/14637/1 "2004-11-05T18:22:55Z")

</div>

Thanks for the tips. I looked all around the Internet but couldn't find too  
much on using Tk within Ruby. Today I was trying to add the TkToplevel class  
and utilize the withdraw and deiconify methods. I think I have a decent  
start, as I have the new window created and am now trying to tackle hiding  
the original window. What do you folks recommend in terms of a Ruby/Tk  
reference guide? Should I just pick up an available Perl/Tk guide and adapt  
it for Ruby myself?

> **···**
>
> -----Original Message-----  
> From: Hidetoshi NAGAI [mailto:nagai@ai.kyutech.ac.jp]  
> Sent: Thursday, November 04, 2004 7:24 PM  
> To: ruby-talk@ruby-lang.org  
> Subject: Re: Ruby/TK Question
> 
> Hi,
> 
> From: "Kujawa, Greg" \<Greg.Kujawa@DiamondCellar.com\>  
> Subject: Ruby/TK Question  
> Date: Fri, 5 Nov 2004 02:09:08 +0900  
> Message-ID: \<B058578D93B5D41193840090276AA76769F967@DIAMOND\_EX\>
> 
> > The application is for a survey. I have created an initial window  
> > where the survey taker signs in. They select their name from a  
> > TkListbox object. When they click on a TkButton object the sign in  
> > window exits and I record the appropriate current selection of the  
> > listbox object.
> 
> I recommend you to define a binding to the listbox for more comfortable UI.  
> 😉 For example,  
> ----------------------------------------------------------  
> $empListbox..bind('Double-Button-1', proc{button.invoke})  
> ----------------------------------------------------------
> 
> > My question is how would I go about creating a new window for taking  
> > survey itself and still keep the saved selection of the listbox  
> > object?
> 
> Please use the TkToplevel class. It creates a new window object.  
> Because the window depends on the root (or its parent) widget,  
> when the root widget is destroyed, the window is destroyed too.  
> If you want to hide the root widget, use {TkRoot/TkToplevel}#withdraw  
> and deiconify method.
> 
> > # Add the sign in button  
> > button = TkButton.new(@root) { text "Sign me in!"  
> > command proc {  
> > &nbsp;&nbsp;&nbsp;&nbsp;indexstr = $empListbox.curselection.to\_s;  
> > &nbsp;&nbsp;&nbsp;&nbsp;indexnum = indexstr.to\_i;  
> > &nbsp;&nbsp;&nbsp;&nbsp;$taker=$employee[indexnum].to\_s;  
> > &nbsp;&nbsp;&nbsp;&nbsp;p $taker;  
> > &nbsp;&nbsp;&nbsp;&nbsp;exit
> 
> Probably, this 'exit' exits the application.
> 
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
