Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Calling class's method when button is pressed

Reply
Thread Tools

Calling class's method when button is pressed

 
 
Sujeet Kumar
Guest
Posts: n/a
 
      05-29-2005
Hi
How to call the method of a class when button(TkButton) is pressed.
For example why the following code generate runtime error
bgerror failed to handle background error.
Original error: NoMethodError: undefined method `bpressed' for
Button:Class
Error in bgerror: invoked "break" outside of a loop
when TkButton is pressed.The code is
require 'tk'
class Button
def bpressed
puts "bpressed"
end

root = TkRoot.new(){ title "Buttton"}
button =TkButton.new(root){
text "Button1"
command {Button::bpressed}

}.pack
end
Tk.mainloop

Anyone can explain the error or any other method to call class's function
when TkButton is pressed
Thanks
sujeet



 
Reply With Quote
 
 
 
 
Charles Steinman
Guest
Posts: n/a
 
      05-29-2005

Sujeet Kumar wrote:
> Original error: NoMethodError: undefined method `bpressed' for
> Button:Class
> Error in bgerror: invoked "break" outside of a loop
> when TkButton is pressed.The code is
> require 'tk'
> class Button
> def bpressed
> puts "bpressed"
> end
>
> root = TkRoot.new(){ title "Buttton"}
> button =TkButton.new(root){
> text "Button1"
> command {Button::bpressed}
>
> }.pack
> end
> Tk.mainloop


You are defining bpressed as an instance method, not a class method, of
Button. What you want is this:

class Button
def self.bpressed
puts "bpressed"
end
end

 
Reply With Quote
 
 
 
 
Sujeet Kumar
Guest
Posts: n/a
 
      05-29-2005
Hi
Thanks.It works now
sujeet

> Sujeet Kumar wrote:
>> Original error: NoMethodError: undefined method `bpressed' for
>> Button:Class
>> Error in bgerror: invoked "break" outside of a loop
>> when TkButton is pressed.The code is
>> require 'tk'
>> class Button
>> def bpressed
>> puts "bpressed"
>> end
>>
>> root = TkRoot.new(){ title "Buttton"}
>> button =TkButton.new(root){
>> text "Button1"
>> command {Button::bpressed}
>>
>> }.pack
>> end
>> Tk.mainloop

>
> You are defining bpressed as an instance method, not a class method, of
> Button. What you want is this:
>
> class Button
> def self.bpressed
> puts "bpressed"
> end
> end
>
>





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 button form + which button was pressed Bill_W_Stephens@yahoo.com Javascript 1 04-04-2006 04:25 AM
execute window.open without a button pressed? cgia ASP .Net 2 04-02-2004 10:50 PM
How to detect that a key is being pressed, not HAS been pressed earlier!?? Rune Python 6 01-29-2004 12:39 PM
Previous Link Cached after Browser Back Button pressed Earl Teigrob ASP .Net 0 12-15-2003 06:00 PM
If value in name field in top row disable submit button until add button is pressed or field is cleared. Chuck Javascript 0 11-10-2003 02:23 AM



Advertisments