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