wxRuby 的 RadioBox 问题

发布于 2024-12-06 18:50:18 字数 1992 浏览 0 评论 0 原文

我在 wxRuby 上使用 Wx::RadioBox

我的收音机有一些丑陋的背景和像这样的边框:

与我运行时获得更好样式的演示不同:

在此处输入图像描述

这是我的代码:

#!/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()

这是默认代码:

  • samples/bigdemo/wxRadioBox.rbw
  • 看来这段代码与 C:\[your Ruby Install]\lib\ruby\gems\1.9.1\gems\wxruby-ruby19-2.0.1-x86-mingw32\samples\bigdemo

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

I got a situation on wxRuby using Wx::RadioBox.

My radioboxes got some ugly background & borders like that :

My ugly RadioBoxes

Unlike the demo which got a better style when I run it :

enter image description here

here is my code :

#!/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()

And here is the default code :

  • samples/bigdemo/wxRadioBox.rbw
  • It seem's that this code is different from the one on your wxRuby install present in C:\[your Ruby Install]\lib\ruby\gems\1.9.1\gems\wxruby-ruby19-2.0.1-x86-mingw32\samples\bigdemo

Any help will be highly appreciated because I really don't know why the aspect is so much different?

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

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

发布评论

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

评论(1

路还长,别太狂 2024-12-13 18:50:19

通过在主框架上设置默认背景颜色解决了问题: 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()

Problem solved by setting up a default background color on the main Frame : self.set_background_colour(Wx::NULL_COLOUR)

enter image description here

and here is the code :

#!/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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文