wxPython获得面板的颜色

时间:2017-11-07 17:18:52

标签: wxpython-phoenix

我正在尝试检索wxPython中面板的背景颜色

import wx

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Panel colour')
        panel = MainPanel(self)
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.Add(panel)
        self.SetSizerAndFit(main_sizer)

        self.Centre()
        self.Show()
        print(self.GetBackgroundColour())
        print(panel.GetBackgroundColour())

class MainPanel(wx.Panel):
    def __init__(self, frame):
        wx.Panel.__init__(self, frame)
        lbl_description = wx.StaticText(self, label='Hello world')
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.Add(lbl_description, flag=wx.ALL, border=10)
        self.SetSizer(main_sizer)


if __name__ == "__main__":
    screen_app = wx.App()
    main_frame = MainFrame()
    screen_app.MainLoop()

enter image description here

但我得到的输出是

(225, 225, 225, 255)
(225, 225, 225, 255)
显然,我做错了什么。我应该怎么做到?

1 个答案:

答案 0 :(得分:1)

这些数字为您提供RGB值的颜色。

enter image description here

RGB颜色由红色,绿色和蓝色的三个值定义,从0到255.第四个值是alpha值(透明度)。