首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Wx.Radiobox.SetBackgroundColour(“粉红色”)在鼠标经过之前不会改变RadioButton的颜色

Wx.Radiobox.SetBackgroundColour(“粉红色”)在鼠标经过之前不会改变RadioButton的颜色
EN

Stack Overflow用户
提问于 2014-03-13 03:40:05
回答 1查看 627关注 0票数 1

我已经构建了一个wx.Dialog,其中有一些wx.Radiobox需要验证。如果用户没有做出选择,验证器将不会返回True,并弹出一个wx.MessageBox告诉用户您应该选择什么。同时,背景颜色应该已经改变为粉红色。

这里的问题是当使用RadioBox.SetBackgroundColour("pink")时,RadioBox的标签文本的背景色更改为粉红色,这是完全正常的,但是RadioButton的标签文本的背景色在鼠标经过之前不会改变。

我想知道这是为什么,以及如何解决它。我查过官方文档并搜索过,但什么也没找到。有人想办法吗?

平台是win8.1x64和python 2.7.3和wxpython 2.8.12.1。对于使用独立程序包,python和wxpython的版本都很老。

该对话框如下,非常简单:

代码语言:javascript
代码运行次数:0
运行
复制
class Dlg(wx.Dialog):
    """A simple dialogue box."""

    def __init__(self):
        global app
        app = wx.PySimpleApp()
        wx.Dialog.__init__(self, None,-1)

        self.sizer = wx.FlexGridSizer(cols=1)

    def show(self, cancelBTN=False):
        """Show a dialog with 2 RadioBox"""

        # add two RadioBox

        RadioBox1 = wx.RadioBox(self, -1, label="Wierd color", choices=["", "choice A", "choice B"], validator=RadioObjectValidator())
        RadioBox2 = wx.RadioBox(self, -1, label="Wierd color", choices=["", "choice A", "choice B"], validator=RadioObjectValidator())
        RadioBox1.ShowItem(0, show=False)  # Hide the first choice
        RadioBox2.ShowItem(0, show=False)  # Hide the first choice

        RadioBox1.GetValue = RadioBox1.GetStringSelection
        RadioBox2.GetValue = RadioBox2.GetStringSelection
        self.sizer.Add(RadioBox1, 1, wx.ALIGN_LEFT)
        self.sizer.Add(RadioBox2, 1, wx.ALIGN_LEFT)

        # add buttons for OK

        self.sizer.Add(wx.Button(self, wx.ID_OK), 1, flag=wx.ALIGN_RIGHT)

        self.SetSizerAndFit(self.sizer)

        if self.ShowModal() == wx.ID_OK:
            pass
            # do something

        self.Destroy()

而Validator是这样:

代码语言:javascript
代码运行次数:0
运行
复制
class RadioObjectValidator(wx.PyValidator):
    """ This validator is used to ensure that the user has entered something
        into the text object editor dialog's text field.
    """
    def __init__(self):
        """ Standard constructor.
        """
        wx.PyValidator.__init__(self)

    def Clone(self):
        """ Standard cloner.

            Note that every validator must implement the Clone() method.
        """
        return RadioObjectValidator()

    def Validate(self, win):
        """ Validate the contents of the given RadioBox control.
        """
        RadioBox = self.GetWindow()
        choice = RadioBox.GetValue()

        if not choice:
            wx.MessageBox(u'Choose something please', u'info', wx.OK | wx.ICON_EXCLAMATION)
            RadioBox.SetBackgroundColour("pink")
            RadioBox.SetFocus()
            RadioBox.Refresh()
            return False
        else:
            RadioBox.SetBackgroundColour(
                wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
            RadioBox.Refresh()
            return True

    def TransferToWindow(self):
        """ Transfer data from validator to window.

            The default implementation returns False, indicating that an error
            occurred.  We simply return True, as we don't do any data transfer.
        """
        return True  # Prevent wxDialog from complaining.

    def TransferFromWindow(self):
        """ Transfer data from window to validator.

            The default implementation returns False, indicating that an error
            occurred.  We simply return True, as we don't do any data transfer.
        """
        return True  # Prevent wxDialog from complaining.

然后像这样跑:

代码语言:javascript
代码运行次数:0
运行
复制
if __name__ == "__main__":
    test = Dlg()
    test.show()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-14 02:17:11

这是wxpython2.8.12.1中的一个bug,并在wxpython3.0.0.0中进行了修正,谢谢@GreenAsJade提醒。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22368584

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档