I have been experimenting with dc.DrawPoint() and dc.DrawPointList() but the pixels produced by both methods are not the exact colour as that set in the Pen object.
When I run the example code below, it draws 2 squares on a panel, both using wx.BLACK. The square on the left is drawn using dc.DrawPoint() and the square on the right is drawn using dc.DrawRectangle(). The square on the left is noticeably lighter that the square on the right. The Gpick tool gives ‘#3F3F3F’ for the left square, but the expected ‘#000000’ for the square on the right. In my real application I need to be able to draw scattered individual points, so using DrawRectangle() is not appropriate.
Is there a way to get DrawPoint() to produce pixels in the exact colour set in the pen?
I am using Python 3.6.9 and wxPython 4.0.1 gtk3 on Linux Mint 19.3 on my development PC.
I have tested the code on another PC that has Python 3.8.2 and wxPython 4.0.7 gtk3 on Linux Mint 20 and it gave identical results.
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.SetTitle("draw_point_exp.py")
self.SetSize((275, 175))
self.panel_1 = wx.Panel(self, wx.ID_ANY)
self.close_button = wx.Button(self, wx.ID_ANY, "Close")
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
sizer_2.Add((20, 20), 1, wx.EXPAND, 0)
sizer_2.Add(self.close_button, 0, 0, 0)
sizer_2.Add((20, 20), 1, wx.EXPAND, 0)
sizer_1.Add(sizer_2, 0, wx.BOTTOM | wx.EXPAND | wx.TOP, 8)
self.SetSizer(sizer_1)
self.Layout()
self.Bind(wx.EVT_BUTTON, self.OnClose, self.close_button)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def Draw(self, dc):
bg_brush = wx.Brush(wx.WHITE, wx.BRUSHSTYLE_SOLID)
dc.SetBackground(bg_brush)
dc.Clear()
pen = wx.Pen(wx.BLACK)
dc.SetPen(pen)
brush = wx.Brush(wx.BLACK)
dc.SetBrush(brush)
for y in range(100):
for x in range(100):
dc.DrawPoint(x, y)
dc.DrawRectangle(120, 0, 100, 100)
def OnClose(self, _event):
self.Destroy()
def OnEraseBackground(self, event):
pass
def OnPaint(self, _event):
dc = wx.BufferedPaintDC(self)
self.Draw(dc)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()