LoginSignup
2
2

More than 5 years have passed since last update.

wxRubyでToolbarを表示する

Posted at

ちょっと昔のサンプルだと動かないものが多かったので。
Wx::Toolbar.realize を呼び出さないとアイコンが表示されないようにいつの頃からか変更されたらしい。

toolbar.rb
require 'wx'

class MyApp < Wx::App
  def on_init
    MyFrame.new.show
  end
end

class MyFrame < Wx::Frame
  def initialize
    super(nil, -1, "Toolbar")
    toolbar = create_tool_bar
    toolbar.add_tool(Wx::ID_NEW, 'NEW', Wx::ArtProvider.bitmap(Wx::ART_NEW), 'Toolbar')
    toolbar.realize
  end
end

MyApp.new.main_loop

ArtProviderはいちいちアイコンを探してこなくていい便利な機能。
ファイルも増えないし素敵。
http://wxpython.org/docs/api/wx.ArtProvider-class.html

create_tool_bar の部分は

toolbar.rb
    toolbar = Wx::ToolBar.new(self)
    toolbar.add_tool(Wx::ID_NEW, 'NEW', Wx::ArtProvider.bitmap(Wx::ART_NEW), 'Toolbar')
    toolbar.realize
    self.set_tool_bar(toolbar)

でもOK. どちらも一緒。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2