Python 在鼠标经过之前,wx.Radiobox.SetBackgroundColor(“粉色”)不会更改RadioButton的颜色

Python 在鼠标经过之前,wx.Radiobox.SetBackgroundColor(“粉色”)不会更改RadioButton的颜色,python,wxpython,Python,Wxpython,我已经建立了一个wx.Dialog,其中一些wx.Radiobox需要验证。如果用户没有做出选择,验证程序将不会返回True,并弹出一个wx.MessageBox告诉用户您应该选择某个内容。同时,背景色应已更改为粉红色 这里的问题是在使用RadioBox.SetBackgroundColorPink时,RadioBox标签文本的背景色变为粉红色,这是完全正常的,但RadioButton标签文本的背景色在鼠标经过之前不会改变 我想知道为什么会这样,以及如何修复它。我在官方文件中查过,在谷歌上搜索过

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

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

我想知道为什么会这样,以及如何修复它。我在官方文件中查过,在谷歌上搜索过,但什么也没找到。有人知道吗

该平台是win8.1x64、python 2.7.3和wxpython 2.8.12.1。对于使用Psychopy独立软件包,python和wxpython的版本都非常旧

下面是一个非常简单的对话框:

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()
和验证程序如下所示:

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.
然后简单地像这样运行:

if __name__ == "__main__":
    test = Dlg()
    test.show()

好吧,这是wxpython2.8.12.1中的一个bug,已经在wxpython3.0.0.0中修复了,谢谢@GreenAsJade的提醒。

你能提供一个简单的主包装器,让我们运行你的代码并检查这是否会发生1在所有平台上2调整可能会修复什么。从表面上看,这听起来像是wx中的一个bug。@GreenAsJade感谢您的关注和提醒,在底部添加了一个运行它的简单代码片段,希望这对运行它有帮助——这是一个如此简单的包装,但对于前来帮助您的人来说,最好拥有它,因为弄明白它是非常重要的: