wxPython 改变RadioBox的字体颜色
在这篇文章中,我们将学习如何改变框架中的无线电盒的前景颜色。为了做到这一点,我们将使用SetForegroundColour()方法。SetForegroundColour()函数接受wx.Colour参数,该参数将被用作无线电盒的前景颜色。
语法: wx.RadioBox.SetForegroundColour(self, color)
参数
参数 | 输入类型 | 说明 |
---|---|---|
color | wx.colour | 用来做背景的颜色。 |
代码示例:
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()
输出窗口: