Way to draw specific corners of a rect rounded with wx.DC

I am looking to draw something like the following with a wx.DC:

rect

With

dc.DrawRoundedRectangle(x, y, w, h, 4)

all the corners get rounded.

Is there a way to draw only the top two corners as rounded other than to draw a polygon with dc.DrawPolygon?

I don’t know if there is a built in method to do it, but here is a quick & simple way which just draws a square cornered rectangle across the bottom of a rounded rectangle

import wx

def drawRoundedTopRectangle(dc, x, y, width, height, radius):
    dc.DrawRoundedRectangle(x, y, width, height, radius)
    dc.DrawRectangle(x, y+height-radius, width, radius)

class Mywin(wx.Frame):
    def __init__(self, parent, title):
        super(Mywin, self).__init__(parent, title=title, size=(300, 130))
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Centre()
        self.Show(True)

    def OnPaint(self, e):
        dc = wx.PaintDC(self)
        brush = wx.Brush("white")
        dc.SetBackground(brush)
        dc.Clear()

        colour = wx.Colour(65, 58, 89)
        pen = wx.Pen(colour)
        dc.SetPen(pen)
        brush = wx.Brush(colour)
        dc.SetBrush(brush)
        drawRoundedTopRectangle(dc, 50, 20, 200, 60, 10)

if __name__ == '__main__':
    app = wx.App()
    Mywin(None, 'Drawing demo')
    app.MainLoop()

Screenshot at 2021-03-26 19-24-22

Thanks for the answer, @RichardT. :grinning:

What’s funny is that you’ve actually just described how I’ve been doing it. :laughing:

I was more just wondering if there was some built-in method to do so as this method seems slightly wasteful to draw two rectangles. It seems like there isn’t, so I guess I’ll continue to do it with that method! :grinning:

1 Like