ruby实战手册(22)-wxruby(1)

发布时间 2024-01-10 19:55:11作者: 水宝石

概述

wxRuby3是一个针对Ruby的跨平台GUI库,基于成熟的针对C++的wxWidgets GUI工具包。它尽可能地使用本地小部件,为Windows、OS X和Linux/GTK上的GUI应用程序提供正确的外观、感觉和行为。wxRuby旨在为在Ruby中开发专业标准的桌面应用程序提供一个全面的解决方案。

require 'wx'

Wx::App.run do
  Wx::Frame.new(nil, title: 'Hello world!').show
end

button`

image

require 'wx'

class TheFrame < Wx::Frame
  def initialize(title)
    super(nil, title: title)
    panel = Wx::Panel.new(self)
    button = Wx::Button.new(panel, label: '单击我')
    button.evt_button(Wx::ID_ANY) { Wx.message_box('你好,很高兴认识你', 'Button sample') }
  end
end

Wx::App.run { TheFrame.new('Hello world!').show }