wxClientDCImpl without a window? - wxPyWiki

Hi all,

Issue :

Traceback (most recent call last):

  • File “C:\Users\Data\Desktop\TEST\Customized text\source\sample_one\sample_one.py”, line 72, in OnPaint*
  • dc2 = wx.BufferedPaintDC(self.parent)*
    wx._core.wxAssertionError: C++ assertion ““m_window”” failed at …\src\msw\dcclient.cpp(240) in wxClientDCImpl::DoGetSize(): wxClientDCImpl without a window?

_ The attached source code (or link) works correctly with py3.7 / 3.8 and wxPython 4.06 / 4.07 (Windows, Linux and Mac OS).
_ After wxPython 4.1.0 setup, the code doesn’t work. What to do ?

Source : sample.py (4.3 KB)
or
Link :

Customized text (Phoenix) - wxPyWiki

Thank you in advance.

It has never been valid to create a wx.PaintDC from within the paint event handler for a different window, which is what this line is doing:

        dc2 = wx.BufferedPaintDC(self.parent)

Apparently wx has since added a C++ assertion to make sure that it isn’t done. This may have been one of those things that could accidentally work in some situations on some platforms before, but was never meant to.

The best way (and perhaps only way, if you want it to look good and work well) to put text on a textured or gradient background is to actually draw it in that window, on that background, not on a child widget.