Re: Set grid cell background transparency
ioprst <[email protected]> Wed, 11 Nov 2020 22:48:50 -0800 (PST)
| Newsgroups | gmane.comp.python.wxpython |
|---|---|
| Message-ID | <[email protected]> |
import wx
import wx.grid
def getRGBA(rgb, alpha):
"""Получить цвет rgb с непрозрачностью alpha.
Y = 255 - P * (255 - X), X - RGB item, P - aplha (0...1)
:param tuple rgb:
:param float alpha:
:return: New RGB
:rtype: tuple
"""
return tuple(round(255 - alpha * (255 - v)) for v in rgb)
class Frame(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
grid = wx.grid.Grid(self)
grid.CreateGrid(3, 3)
grid.SetCellBackgroundColour(0, 0, wx.Colour(255, 0, 0, 0))
grid.SetCellBackgroundColour(1, 0, wx.Colour((255, 0, 0, 127)))
grid.SetCellBackgroundColour(2, 0, wx.Colour(255, 0, 0, 255))
grid.SetCellBackgroundColour(0, 1, wx.Colour(getRGBA((255, 0, 0),
1)))
grid.SetCellBackgroundColour(1, 1, wx.Colour(getRGBA((255, 0, 0),
0.5)))
grid.SetCellBackgroundColour(2, 1, wx.Colour(getRGBA((255, 0, 0),
0)))
if __name__ == '__main__':
app = wx.App()
frame = Frame(None)
frame.Show()
app.MainLoop()
[image: Снимок.PNG]
--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/8a05f6ae-c693-4296-9d46-ca7701308f38n%40googlegroups.com.
Снимок.PNG
(image/png, 12.5 KB) - not displayed