0

我在 wxRuby 上使用Wx::RadioBox.

我的单选框有一些像这样的丑陋背景和边框:

我丑陋的 RadioBoxes

与我运行它时获得更好风格的演示不同:

在此处输入图像描述

这是我的代码:

#!/usr/bin/env ruby
# coding: utf-8

require 'wx'
include Wx

class MainFrame < Frame
    def initialize()
    super(nil, :title => "Title", :size => [ 480, 400 ])
        #sizer = Wx::BoxSizer.new(Wx::VERTICAL)
        sampleList = ["Choice1","Choice2","Choice3"]
    rb = Wx::RadioBox.new(self, -1, "Title1", Wx::Point.new(15,20), Wx::Size.new(100,200), sampleList, 1, Wx::RA_SPECIFY_COLS, DEFAULT_VALIDATOR, "Name1")
        evt_radiobox(rb) {|event, other| on_debug(sampleList[event.get_int()].to_s(), rb.name.to_s())}
        #sizer.add(rb, 0, Wx::ALL, 20)
    rb2 = Wx::RadioBox.new(self, -1, "Title2", Wx::Point.new(150,20), Wx::Size.new(100,200), sampleList, 1, Wx::RA_SPECIFY_COLS, DEFAULT_VALIDATOR, "Name2")
        evt_radiobox(rb2) {|event| on_debug(sampleList[event.get_int()].to_s(), rb2.name.to_s())}
        #sizer.add(rb2, 0, Wx::ALL, 20)
        #set_sizer(sizer)
    #sizer.fit(self)
        #sizer.layout()
  end
  
  # show a 'Debug' dialog
  def on_debug(*params)
    Wx::message_box("Debug :\n\r\n\r#{params.inspect}",
        "Debug Box",
        ICON_INFORMATION|OK)
  end
end


class MyApp < App
    def on_init
    frame = MainFrame.new
    frame.show
    end
end
MyApp.new.main_loop()

这是默认代码:

  • 样本/bigdemo/wxRadioBox.rbw
  • 似乎此代码与您安装的 wxRuby 中的代码不同C:\[your Ruby Install]\lib\ruby\gems\1.9.1\gems\wxruby-ruby19-2.0.1-x86-mingw32\samples\bigdemo

任何帮助将不胜感激,因为我真的不知道为什么这方面有很大不同?

4

1 回答 1

0

通过在主 Frame 上设置默认背景颜色解决了问题:self.set_background_colour(Wx::NULL_COLOUR)

在此处输入图像描述

这是代码:

#!/usr/bin/env ruby
# coding: utf-8

require 'wx'
include Wx

class MainFrame < Frame
    def initialize()
    super(nil, :title => "Title", :size => [ 480, 400 ])
        #sizer = Wx::BoxSizer.new(Wx::VERTICAL)
    self.set_background_colour(Wx::NULL_COLOUR)
        sampleList = ["Choice1","Choice2","Choice3"]
    rb = Wx::RadioBox.new(self, -1, "Title1", Wx::Point.new(15,20), Wx::Size.new(100,200), sampleList, 1, Wx::RA_SPECIFY_COLS, DEFAULT_VALIDATOR, "Name1")
        evt_radiobox(rb) {|event, other| on_debug(sampleList[event.get_int()].to_s(), rb.name.to_s())}
        #sizer.add(rb, 0, Wx::ALL, 20)
    rb2 = Wx::RadioBox.new(self, -1, "Title2", Wx::Point.new(150,20), Wx::Size.new(100,200), sampleList, 1, Wx::RA_SPECIFY_COLS, DEFAULT_VALIDATOR, "Name2")
        evt_radiobox(rb2) {|event| on_debug(sampleList[event.get_int()].to_s(), rb2.name.to_s())}
        #sizer.add(rb2, 0, Wx::ALL, 20)
        #set_sizer(sizer)
    #sizer.fit(self)
        #sizer.layout()
  end

  # show a 'Debug' dialog
  def on_debug(*params)
    Wx::message_box("Debug :\n\r\n\r#{params.inspect}",
        "Debug Box",
        ICON_INFORMATION|OK)
  end
end


class MyApp < App
    def on_init
    frame = MainFrame.new
    frame.show
   end
end
MyApp.new.main_loop()
于 2011-09-27T07:27:34.523 回答