When I press MSG or EXIT buttons I get undefined method errrs for the
programs domsg and doexit respectively. They are public methods so they
should be quite visible. Code follows - pls tell what I am doing wrong.
thanks in advance.
Joe
class MyForm
def domsg
puts “domsg called”
lbl.configure(“text”=>“Goodbye cruel world\nGoing down real soon”)
t=Time.now.asctime
t=t.split(" “)
puts t[0]+” “+t[1]+” “+t[2]+” “+t[3]
end
def doexit
puts “doexit called”
t=Time.now.asctime
t=t.split(” “)
puts t[0]+” “+t[1]+” “+t[2]+” "+t[3]
puts “…going down!..crash!”
exit
end
def initialize
ph= {‘padx’ =>10, ‘pady’ =>10}
root=TkRoot.new { title “NEAT!” }
@variable1 = TkVariable.new
@variable2 = TkVariable.new
top = TkFrame.new{root;(height 250;width 250)}
lbl=Tk::Tile::Label.new(top) {
text ‘Hello World! This is really neat stuff!’
}
lbl.place(‘height’ =>35,
‘width’ =>200,
‘x’ =>35,
‘y’ =>65
)
@entry1=TkEntry.new{top;textvariable @variable1; pack(ph)}
@entry1.place(‘height’ => 25,
‘width’ => 150,
‘x’ => 10,
‘y’ => 10)
@entry1.pack(ph)
@entry2=TkEntry.new{top;textvariable @variable2; pack(ph)}
@entry2.place(‘height’ => 25,
‘width’ => 150,
‘x’ => 10,
‘y’ => 40)
@entry2.pack(ph)
b1=TkButton.new(top) {text ‘MSG’ ;command {MyForm.domsg} ;pack ph}
b1.place(‘height’ =>25,
‘width’ =>100,
‘x’ =>50,
‘y’ =>100)
b2=TkButton.new(top) {text ‘EXIT’;command {MyForm.doexit};pack ph}
b2.place(‘height’ =>25,
‘width’ =>100,
‘x’ =>50,
‘y’ =>150)
top.pack(‘fill’=>‘both’, ‘side’ =>‘top’)
end
end
MyForm.new
tk.mainloop