wxPython – wx.RadioButton 中的 GetClassDefaultAttributes()
Python提供了wxpython 包,它允许我们创建一个功能强大的图形用户界面。它被实现为一组扩展模块,这些模块包装了用 C++ 编写的 wxWidgets 库的 GUI 组件。它是Python的跨平台GUI工具包,Phoenix版Phoenix是改进的下一代wxPython,主要关注速度、可维护性和可扩展性。
在本文中,我们将学习与 wxPython 的wx.RadioButton类关联的GetClassDefaultAttributes()函数。 GetClassDefaultAttributes()函数用于返回wx.VisualAttributes 对象以获取与单选按钮关联的背景颜色、前景色和字体等属性。
Syntax: wx.RadioButton.GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)
Parameters:
Parameter Input Type Description variant WindowVariant Variant for Radio Button.
Return Type: wx.VisualAttributes
代码 :
Python3
# importing wx library
import wx
APP_EXIT = 1
# create an Example class
class Example(wx.Frame):
# constructor
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
# method calling
self.InitUI()
# method for user interface creation
def InitUI(self):
# create parent panel for radio buttons
self.pnl = wx.Panel(self)
# create radio button
self.rb = wx.RadioButton()
self.rb.Create(self.pnl, id = 1 ,
label = "Radio",
pos = (20,20))
# set background colour to blue
self.rb.SetBackgroundColour((0, 0,
255, 255))
# set foreground colour to white
self.rb.SetForegroundColour((255, 255,
255, 255))
# create wx.VisualAttributes object
v = self.rb.GetClassDefaultAttributes()
# print background colour
print(v.colBg)
# print foreground colour
print(v.colFg)
# main function
def main():
# create an App object
app = wx.App()
# create an Example object
ex = Example(None)
ex.Show()
# running an app
app.MainLoop()
# Driver code
if __name__ == '__main__':
# main function call
main()
输出:
(0,0,255,255, 255)
(255, 255, 255, 255)