wxPython - 更改单选按钮的背景颜色
在本文中,我们将了解如何更改单选按钮的背景颜色。我们将使用 SetBackgroundColour()函数设置窗口的背景颜色。
请注意,与 SetForegroundColour 一样,设置本机控件的背景颜色可能不会影响整个控件,并且可能根本不受支持,具体取决于控件和平台。
Syntax: wx.StaticText.SetBackgroundColour(self, colour)
Parameters:
Parameter Input Type Description colour wx.Colour Colour for background of static text.
Return type bool
Returns True if the colour was really changed, False if it was already set to this colour and nothing was done.
代码示例:
Python3
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 for radio buttons
self.pnl = wx.Panel(self)
# create radio button in frame
self.rb1 = wx.RadioButton(self.pnl, label ='Btn1',
pos =(30, 10), size =(100, 20))
# set background colour to yellow (r, g, b, a)
self.rb1.SetBackgroundColour((233, 227, 100, 255))
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: