ruby/tk How do I keep program running with focus after runningexternal progam

E

Ed Redman

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
 
M

Morton Goldberg

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}`}

It seems to work if I change the above line to

toprun.command { system $text.value }
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

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

Similar Threads


Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top