Trying to understand menus in ruby/tk through examples

Can anyone explain why with the first two ‘command’ lines
the program works. but with the third ‘command’ line it doesnt?

Im thinking im missing something in packing or definition?
What Am I not getting?

require ‘tk’

root=TkRoot.new{title “Níl aon tintéan mar do thintéan féin.”}
canvas = TkCanvas.new.pack(‘fill’=>‘both’, ‘expand’=>‘true’)
menuline = TkFrame.new(root, ‘borderwidth’=>2)
.place(‘anchor’=>‘nw’, ‘relx’=>0.0, ‘rely’=>0.0,
‘relwidth’=>1.0)
TkMenubutton.new(menuline) { |mb|
text “File”
underline 0
menu TkMenu.new(mb) {
add ‘command’,
#label, variable, value, underline, command.
‘label’ => ‘Save to DB’,
‘underline’ => 0,
‘command’ => proc { p “Save to database”; }
add ‘separator’
add ‘command’,
‘label’ => ‘Load from DB’,
‘underline’ => 0,
‘command’ => proc { p “Load from database”; }
add ‘command’
‘label’ => ‘Exit program’,
‘underline’ => 0,
‘command’ => proc{exit}
}
pack(‘side’ => ‘left’, ‘padx’ => ‘1m’)
}

canvas.pack
#show gif on the canvas
image = TkPhotoImage.new(‘file’ => ‘red_pen.gif’)
t=TkcImage.new(canvas, 100, 100,
‘image’ => image)
#end of show gif code.
#code to place a label to show text
TkLabel.new {
text “This is a label”
font TkFont.new(‘times 10 normal’)
}.pack
#end of code to show text
canvas.focus

root.bind(‘Any-Key-s’, proc{|e| puts e.inspect; TkcRectangle.new(canvas,
e.x,e.y,e.x-5, e.y-5)})

Tk.mainloop

Mer G. wrote:

Can anyone explain why with the first two ‘command’ lines
the program works. but with the third ‘command’ line it doesnt?

/ …

‘command’ => proc { p “Load from database”; }
add ‘command’
‘label’ => ‘Exit program’,
‘underline’ => 0,
‘command’ => proc{exit}

There’s not enough code to create a working example, so this is just a
guess, but I would ask where "exit’ is defined.

Paul L. wrote:

Mer G. wrote:

Can anyone explain why with the first two ‘command’ lines
the program works. but with the third ‘command’ line it doesnt?

/ …

‘command’ => proc { p “Load from database”; }
add ‘command’
‘label’ => ‘Exit program’,
‘underline’ => 0,
‘command’ => proc{exit}

There’s not enough code to create a working example, so this is just a
guess, but I would ask where "exit’ is defined.

so the problem would be there?
Ill check throught that tomorrow. Ill post it again if im still having
problems.

Mer G. wrote:

/ …

‘command’ => proc { p “Load from database”; }
add ‘command’
‘label’ => ‘Exit program’,
‘underline’ => 0,
‘command’ => proc{exit}

There’s not enough code to create a working example, so this is just a
guess, but I would ask where "exit’ is defined.

so the problem would be there?

That depends. It depends on what you mean when you say it doesn’t work.
Obviously if you call “exit” and “exit” has been redefined, or hangs for
some reason, you will get the symptom that the application doesn’t exit.
It
might be a good idea to trace the action to see where it goes.

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