How to change button text in Shoes?

Once the button is created in Shoes, is it possible to change the text? I tried modifying the text key in the style of the button --@button.style.inspect confirms that the text has been changed, but the button still shows the source text.

+3
source share
2 answers

I did not understand how to change the text on an existing button. I suspect this is not yet supported. You can create a new button and replace the old one. Unfortunately, at least on Windows, deleting a button combines all click events. I have not tried this on another platform, but maybe it will work. Try something like this:

Shoes.app do
  para 'This is some text.'

  @btn = button 'a' do |btn|
    alert 'Hello, World!'
  end

  para 'Blah blah blah'

  button 'Change!' do |btn|
    old = @btn
    new_style = old.style.dup
    txt = new_style[:text].next!
    old.parent.before(old) do
      @btn = button txt, new_style
    end
    old.remove #This messes up the click events on Windows.
  end

end
+2
source

, . , . Green Shoes GTK2, GTK2, GTK2, .

require 'green_shoes'

Shoes.app do
  @btn = button('old text ') {|btn|alert('Hello, World!')}
  button('Change!') {|btn|@btn.real.set_label("new")}
end
0

Source: https://habr.com/ru/post/1714751/


All Articles