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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs