📜  wxPython - 更改 RadioBox 的字体颜色

📅  最后修改于: 2022-05-13 01:55:46.567000             🧑  作者: Mango

wxPython - 更改 RadioBox 的字体颜色

在本文中,我们将学习如何更改框架中存在的 Radio Box 的前景色。为此,我们将使用 SetForegroundColour() 方法。 SetForegroundColour()函数接受 wx.Colour 参数,该参数将用作 Radio Box 的前景色。

代码示例:

Python3
import wx
 
 
class FrameUI(wx.Frame):
 
    def __init__(self, parent, title):
        super(FrameUI, self).__init__(parent, title = title, size =(300, 200))
 
        # function for in-frame components
        self.InitUI()
 
    def InitUI(self):
        # parent panel for radio box
        pnl = wx.Panel(self)
 
        # list of choices
        lblList = ['Radio One', 'Radio Two']
 
        # create radio box containing above list
        self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(80, 10), choices = lblList,
                                          majorDimension = 1, style = wx.RA_SPECIFY_ROWS)
 
        # change foreground colour for radio box
        self.rbox.SetForegroundColour((0, 0, 255, 255))
 
        # set frame in centre
        self.Centre()
        # set size of frame
        self.SetSize((400, 250))
        # show output frame
        self.Show(True)
 
 
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')
ex.MainLoop()


输出窗口: