wxPython - 更改单选按钮的字体颜色
在本文中,我们将学习如何更改单选按钮的前景或字体颜色。为了改变单选按钮的前景色,我们将使用 SetForegroundColour()函数。 SetForegroundColour()函数设置窗口的前景色。
前景色的含义因窗口类别而异;它可能是文本颜色或其他颜色,也可能根本不使用。此外,并非所有本机控件都支持更改其前景色,因此此方法可能仅部分更改其颜色,甚至根本不更改。
Syntax: wx.RadioButton.SetForegroundColour(self, colour)
Parameters:
Parameter | Input Type | Description |
---|---|---|
colour | wx.Colour | colour for the background. |
Return: True if the colour was really changed, False if it was already set to this colour and nothing was done.
Return Type: bool
代码示例:
import wx
APP_EXIT = 1
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
# create parent panel in the frame
self.pnl = wx.Panel(self)
# create radio button at position (30, 10)
self.rb1 = wx.RadioButton(self.pnl, label ='Btn1',
pos =(30, 10), size =(100, 20))
# change background colour
self.rb1.SetBackgroundColour((233, 227, 100, 255))
# change foreground colour
self.rb1.SetForegroundColour((0, 0, 255, 255))
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: