Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Trying to understand menus in ruby/tk through examples
Mer Gilmartin
9/27/2006 11:07:00 AM
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
--
Posted via
http://www.ruby-...
.
3 Answers
Paul Lutus
9/27/2006 3:35:00 PM
0
Mer Gilmartin 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 Lutus
http://www.ara...
Mer Gilmartin
9/27/2006 4:18:00 PM
0
Paul Lutus wrote:
> Mer Gilmartin 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.
--
Posted via
http://www.ruby-...
.
Paul Lutus
9/27/2006 7:21:00 PM
0
Mer Gilmartin 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.
--
Paul Lutus
http://www.ara...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Trying to understand menus in ruby/tk through examples
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password