Trying to understand menus in ruby/tk through examples

M

Mer Gilmartin

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
 
M

Mer Gilmartin

Paul said:
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.
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top