Hi all, I create 3 buttons. If I click @button_start , at button_word will change its text one by one based on an array. If I click @button_end the program will end. My problem here is that the word on @button_word doesn''t change one by one, instead they all show up at the same time. Any idea? Thanks, Li ################################################### #create 3 buttons @button_start=FXButton.new(self,''start'') @button_end=FXButton.new(self,''end'') @button_word=FXButton.new(self,''reading words'') # change the text on @button_word one by one slice=%w{A,B,C,D,E} @button_start.connect(SEL_COMMAND) do|sender,selector,data| slice.each do |letter| @button_word.text=letter sleep 2 end end @button_end.connect(SEL_COMMAND) do|sender,selector,data| exit end
Lyle Johnson
2008-Nov-01 23:29 UTC
[fxruby-users] how to change a button''s text one by one
On Nov 1, 2008, at 5:12 PM, chen li wrote:> I create 3 buttons. If I click @button_start , at button_word will > change its text one by one based on an array. If I click @button_end > the program will end. My problem here is that the word on > @button_word doesn''t change one by one, instead they all show up at > the same time.Your definition of "slice" is an array containing one element: slice = %w{A,B,C,D,E} This evaluates to an array with one element, whose value is the string "A,B,C,D,E". I think what you''re going for is: slice = %w{A B C D E} or just: slice = ["A", "B", "C", "D", "E"] Hope this helps, Lyle
Hi Chen, I suggest you use timer to show the text. chen li wrote:> Hi all, > > > I create 3 buttons. If I click @button_start , at button_word will change its text one by one based on an array. If I click @button_end the program will end. My problem here is that the word on @button_word doesn''t change one by one, instead they all show up at the same time. > > Any idea? > > > Thanks, > > Li > > > ################################################### > #create 3 buttons > @button_start=FXButton.new(self,''start'') > @button_end=FXButton.new(self,''end'') > @button_word=FXButton.new(self,''reading words'') > > # change the text on @button_word one by one > slice=%w{A,B,C,D,E} > > @button_start.connect(SEL_COMMAND) do|sender,selector,data| > slice.each do |letter| > @button_word.text=letter > sleep 2 > end > > end > > > > > > @button_end.connect(SEL_COMMAND) do|sender,selector,data| > exit > > end-- Regards Soumyanath Chatterjee [http://www.soumya.name] Question _your own_ authority.
Hi Lyle, I change to slice = ["A", "B", "C", "D", "E"]. But strange thing still happens: I can see the button change to the last item ''E'' from ''reading word'', but not to the other itmes of A , B, C, D. Another question: I read API about FXButton. There are no instance methods such as #text in this class. But when I query Ruby on it by code line: button.public_methods.size it return 414 methods. Where are these methods defined, by their ancestors and mixins? Thanks, Li