# Ruby/tk How do I keep program running with focus after run

**URL:** <https://www.ruby-forum.com/t/ruby-tk-how-do-i-keep-program-running-with-focus-after-run/114372>\
**Category:** Ruby\
**Created:** [September 11, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/ruby-tk-how-do-i-keep-program-running-with-focus-after-run/114372 "2007-09-11T23:05:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Redman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@Ed\_Redman](https://www.ruby-forum.com/u/Ed_Redman)\
**Post date:** [September 11, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/ruby-tk-how-do-i-keep-program-running-with-focus-after-run/114372/1 "2007-09-11T23:05:31Z")

</div>

Hello all  
I have written a simple program to run an external system application.

When the application finishes the focus does not return to the ruby/tk  
application. It does not function. Eventually it quits but not in a  
proper fashion.

Here is the program. I hope someone can help.

#!/usr/bin/ruby

require ‘tk’

root = TkRoot.new  
root.title “Execute Program”  
$text = TkVariable.new  
frame = TkFrame.new(root)  
frame.borderwidth 10  
frame.pack( ‘side’ =\> ‘top’)  
frame.pack(‘fill’ =\> ‘x’)

toprun = TkButton.new(frame)  
toprun.text “Run it”  
toprun.command{ `#{$text}`}  
toprun.pack( ‘side’ =\> “right”)

topquit = TkButton.new(frame)  
topquit.text “Exit”  
topquit.command{ exit }  
topquit.pack(‘side’ =\> “right”)

label = TkLabel.new(frame)  
label.text “Command”  
label.pack(“padx” =\> 0)

entry = TkEntry.new(frame)  
entry.textvariable $text  
entry.width 20  
entry.relief ‘sunken’  
entry.pack(“side” =\> “left”)  
entry.pack(“fill” =\> “x”)  
entry.pack(“expand” =\> “true”)

Tk.mainloop

---

<div class="post-metadata">

**Author:** ![Ed\_Redman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b4bc9f/32.png) [@Ed\_Redman](https://www.ruby-forum.com/u/Ed_Redman)\
**Post date:** [September 12, 2007, 12:30am UTC](https://www.ruby-forum.com/t/ruby-tk-how-do-i-keep-program-running-with-focus-after-run/114372/2 "2007-09-12T00:30:39Z")

</div>

On Sep 11, 2007, at 5:05 PM, Ed Redman wrote:

> toprun = TkButton.new(frame)  
> toprun.text “Run it”  
> toprun.command{ `#{$text}`}

It seems to work if I change the above line to

```
toprun.command { system $text.value }

```

> entry = TkEntry.new(frame)  
> entry.textvariable $text  
> entry.width 20  
> entry.relief ‘sunken’  
> entry.pack(“side” =\> “left”)  
> entry.pack(“fill” =\> “x”)  
> entry.pack(“expand” =\> “true”)
> 
> Tk.mainloop

Regards, Morton
