如何更改 Shoes 中的按钮文本?

发布于 2024-08-01 13:38:02 字数 219 浏览 2 评论 0原文

在 Shoes 中创建按钮后,是否可以更改文本? 我尝试修改按钮 [电子邮件受保护] 中的 :text 键确认文本已更改 - 但按钮仍显示原始文本。

Once a button is created in Shoes, is it possible to change the text? I've tried modifying the :text key in the button [email protected] confirms the text is changed--but the button still shows the original text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无远思近则忧 2024-08-08 13:38:02

我还没弄清楚如何更改现有按钮上的文本。 我怀疑它目前还不支持。 您可以创建一个新按钮并替换旧按钮。 不幸的是,至少在 Windows 上,删除按钮会扰乱所有单击事件。 我还没有在其他平台上尝试过,但也许它会起作用。 尝试这样的事情:

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

I haven't figured out how to change the text on the existing button. I suspect it just isn't supported as of yet. You could create a new button and replace the old one. Unfortunately, at least on Windows, removing a button mucks up all the click events. I haven't tried it on another platform, but maybe it'll 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
断桥再见 2024-08-08 13:38:02

这是一个很老的问题,但有一个解决方案。
你没有提到你的鞋子颜色,所以我用绿色。
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

A very old question, but there is a solution.
You didn't mention your shoes color, so i use green.
Green Shoes is based on GTK2, so you can use the methods of GTK2 if you extract the GTK2 object like this.

require 'green_shoes'

Shoes.app do
  @btn = button('old text ') {|btn|alert('Hello, World!')}
  button('Change!') {|btn|@btn.real.set_label("new")}
end
〃温暖了心ぐ 2024-08-08 13:38:02

我找到了一种模拟更改按钮文本的方法,方法是将其替换为具有与旧按钮相同操作的新按钮。

该按钮首先从其容器(堆栈或流)中删除,然后添加一个新按钮。 这个新按钮将出现在容器的末尾,因此可能需要专门为此按钮创建一个堆栈或流。

# Display 2 buttons, A and B.  Initially button A has text "a".
# Pressing the top button, A, just shows the value of @ch (which is
# the text of the button) on the console.
# Pressing the second button appears to change the text of button A.
# It actually replaces it with a new button with the same action as the old.
Shoes.app do
  def button_a_function
    info("click!  #{@ch}")
  end
  @ch = "a"
  @the_flow = flow do
    para "Button A, whose to be changed"
    @b1 = button @ch do
      button_a_function
    end
  end
  flow do
    para "Button B"
    @b2 = button("Change it") {
      @ch.succ!
      @b1.remove
      @b1 = @the_flow.button (@ch) {
        button_a_function
      }
    }
  end
end

I found a way of simulating changing the text of a button by replacing it with a new button with the same action as the old.

The button is first removed from its container (a stack or a flow) and then a new one is added. This new button will appear at the end of the container, so it may be necessary to have a stack or flow just for this button.

# Display 2 buttons, A and B.  Initially button A has text "a".
# Pressing the top button, A, just shows the value of @ch (which is
# the text of the button) on the console.
# Pressing the second button appears to change the text of button A.
# It actually replaces it with a new button with the same action as the old.
Shoes.app do
  def button_a_function
    info("click!  #{@ch}")
  end
  @ch = "a"
  @the_flow = flow do
    para "Button A, whose to be changed"
    @b1 = button @ch do
      button_a_function
    end
  end
  flow do
    para "Button B"
    @b2 = button("Change it") {
      @ch.succ!
      @b1.remove
      @b1 = @the_flow.button (@ch) {
        button_a_function
      }
    }
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文