= How to create a basic drawing (Phoenix) = '''Keywords :''' Drawing, PaintDC, GCDC, Graphic context. <<TableOfContents>> -------- = Demonstrating : = __'''''Tested''' py3.x, wx4.x and Win10. ''__ Are you ready to use some samples ? ;) Test, modify, correct, complete, improve and share your discoveries ! (!) -------- == Sample one == {{attachment:img_sample_one.png}} {{{#!python # sample_one.py import wx # class MyPanel # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.Bind(wx.EVT_PAINT, self.OnPaint) #----------------------------------------------------------------------- def OnPaint(self, event): """ ... """ pdc = wx.PaintDC(self) gc = wx.GCDC(pdc) gc.Clear() #------------ # Square. #------------ gc.SetPen(wx.Pen("red", 2)) gc.SetBrush(wx.Brush("yellow")) x = 100 y = 30 w = 50 h = 50 # pt, sz # or # rect # or # x, y, width, height gc.DrawRectangle(x , y, w, h) gc.DrawText("Square", int(x+w+10), int(y+h/2)) #------------ # Rectangle. #------------ gc.SetPen(wx.Pen("black", 2)) gc.SetBrush(wx.Brush((0, 255, 255, 255))) x = 100 y = 130 w = 100 h = 50 # pt, sz # or # rect # or # x, y, width, height gc.DrawRectangle(x , y, w, h) gc.DrawText("Rectangle", int(x+w+10), int(y+h/2)) #------------ # Rounded rectangle. #------------ gc.SetPen(wx.Pen("black", 2)) gc.SetBrush(wx.Brush((255, 0, 255, 128))) x = 100 y = 230 w = 100 h = 50 r = 8 # pt, sz, radius # or # rect, radius # or # x, y, width, height, radius) gc.DrawRoundedRectangle(x, y, w, h, r) gc.DrawText("Rounded rectangle", int(x+w+10), int(y+h/2)) #------------ # Ellipse. #------------ gc.SetPen(wx.Pen("gray", 2)) gc.SetBrush(wx.Brush("green")) x = 100 y = 330 w = 100 h = 50 # pt, size # or # rect # or # x, y, width, height gc.DrawEllipse(x, y, w, h) gc.DrawText("Ellipse", int(x+w+10), int(y+h/2)) #------------ # Circle. #------------ gc.SetPen(wx.Pen("red", 2)) gc.SetBrush(wx.Brush("#ffc0cb")) x = 130 y = 455 r = 35 # pt, radius # or # x, y, radius gc.DrawCircle(x, y, r) gc.DrawText("Circle", int(x+45), int(y)) #------------ # Line. #------------ gc.SetPen(wx.Pen("purple", 4)) x1 = 100 y1 = 545 x2 = 200 y2 = 545 # pt1, pt2 # or # x1, y1, x2, y2 gc.DrawLine(x1, y1, x2, y2) gc.DrawText("Line", int(x+w-10), int(y+80)) #------------ # Triangle. #------------ gc.SetPen(wx.Pen("blue", 2)) gc.SetBrush(wx.Brush((150, 150, 150, 128))) points = [(80, 80), (10, 10), (80, 10), (80, 80) ] x = 90 y = 580 # points, xoffset=0, yoffset=0, fill_style=ODDEVEN_RULE gc.DrawPolygon(points, x, y) gc.DrawText("Triangle", int(x+w-5), int(y+h/2)) #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #------------ self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) #------------ self.Panel = MyPanel(self) #--------------------------------------------------------------------------- class MyApp(wx.App): """ ... """ def OnInit(self): #------------ frame = MyFrame(None, title="Sample_one", size=(380, 750)) self.SetTopWindow(frame) frame.Show(True) return True #--------------------------------------------------------------------------- def main(): app = MyApp(False) app.MainLoop() #--------------------------------------------------------------------------- if __name__ == "__main__" : main() }}} -------- == Sample two == {{attachment:img_sample_two.png}} {{{#!python # sample_two.py import wx # class MyPanel # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.Bind(wx.EVT_PAINT, self.OnPaint) #----------------------------------------------------------------------- def OnPaint(self, event): """ ... """ pdc = wx.PaintDC(self) gc = wx.GCDC(pdc) gc.Clear() #------------ # Bitmap. #------------ x = 100 y = 30 # bmp, pt, useMask=False # or # bitmap, x, y, useMask=False gc.DrawBitmap(wx.Bitmap("./Bitmaps/python.png"), x, y, True) gc.DrawText("Bitmap", int(x+150), int(y+20)) #------------ # Icon. #------------ x = 100 y = 130 # icon, pt # or # icon, x, y gc.DrawIcon(wx.Icon("./icons/icon_wxWidgets.ico"), x, y) gc.DrawText("Icon", int(x+75), int(y+20)) #------------ # Arc. #------------ gc.SetPen(wx.Pen("black", 2)) gc.SetBrush(wx.Brush((204, 85, 248, 128))) x1 = 100 y1 = 260 x2 = 340 y2 = 335 x = 160 y = 220 # ptStart, ptEnd, centre # or # xStart, yStart, xEnd, yEnd, xc, yc gc.DrawArc(x1, y1, x2, y2, x, y) gc.DrawText("Arc", int(x+80), int(y+30)) #------------ # Polygon. #------------ gc.SetPen(wx.Pen("blue", 2)) gc.SetBrush(wx.Brush("#cacaca")) points = [(80, 140), (130, 170), (130, 140), (170, 110) ] x = 20 y = 220 # points, xoffset=0, yoffset=0, fill_style=ODDEVEN_RULE gc.DrawPolygon(points, x, y) gc.DrawText("Polygon", int(x+150), int(y+140)) #------------ # Spline. #------------ gc.SetPen(wx.Pen("red", 2)) gc.SetBrush(wx.Brush("pink")) points = [(100, 435), (140, 435), (145, 495), (185, 495) ] # x1, y1, x2, y2, x3, y3 # or # points gc.DrawSpline(points) gc.DrawText("Spline", int(x+180), int(y+250)) #------------ # Point. #------------ gc.SetPen(wx.Pen("purple", 80)) x = 100 y = 555 # pt # or # x, y gc.DrawPoint (x, y) gc.DrawText("Point", int(x+20), int(y-10)) #------------ # Text. #------------ x = 150 y = 620 gc.DrawText("Text", int(x+100), int(y)) gc.SetTextForeground("red") font = wx.Font(36, wx.ROMAN, wx.ITALIC, wx.NORMAL) gc.SetFont(font) # text, pt # or # text, x, y gc.DrawText("Hello !", x-50, y-20) #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #------------ self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) #------------ self.Panel = MyPanel(self) #--------------------------------------------------------------------------- class MyApp(wx.App): """ ... """ def OnInit(self): #------------ frame = MyFrame(None, title="Sample_two", size=(380, 750)) self.SetTopWindow(frame) frame.Show(True) return True #--------------------------------------------------------------------------- def main(): app = MyApp(False) app.MainLoop() #--------------------------------------------------------------------------- if __name__ == "__main__" : main() }}} -------- == Sample three == {{attachment:img_sample_three.png}} {{{#!python # sample_three.py import wx # class MyPanel # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyPanel(wx.Panel): def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.Bind(wx.EVT_PAINT, self.OnPaint) #----------------------------------------------------------------------- def OnPaint(self, event): """ ... """ pdc = wx.PaintDC(self) gc = wx.GCDC(pdc) gc.Clear() #------------ # Elliptic arc. #------------ pen = wx.Pen("black", 2, wx.SOLID) pen.SetCap(wx.CAP_BUTT) gc.SetPen(pen) gc.SetBrush(wx.GREEN_BRUSH) x = 100 y = 30 w = 50 h = 50 r = 270 # pt, sz, sa, ea # or # x, y , width, height, start, end gc.DrawEllipticArc(x, y, w, h, 0, r) gc.DrawText("Elliptic arc", int(x+w+10), int(y+h/2)) #------------ # Lines. #------------ gc.SetPen(wx.Pen("purple", 4)) points = [(20, 160), (100, 160), (20, 110), (100, 110) ] x = 90 y = 20 # points, xoffset=0, yoffset=0 gc.DrawLines(points, x, y) gc.DrawText("Lines", int(x+120), int(y+125)) #------------ # Gradient fill linear. #------------ x = 100 y = 240 w = 100 h = 100 gc.GradientFillLinear((x, y, w, h), "#ff6b1a", "#000000", wx.NORTH) # rect, initialColour, destColour, nDirection=RIGHT) gc.DrawText("Gradient fill linear", int(x+115), int(y+40)) #------------ # Gradient fill concentric. #------------ x = 100 y = 380 w = 100 h = 100 # Note : currently this function is very slow, # don’t use it for real-time drawing. # rect, initialColour, destColour # or # rect, initialColour, destColour gc.GradientFillConcentric((x, y, w, h), "#61c3ff", "#000000", (50, 50)) # rect, initialColour, destColour, circleCenter) gc.DrawText("Gradient fill concentric", int(x+115), int(y+40)) #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #------------ self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) #------------ self.Panel = MyPanel(self) #--------------------------------------------------------------------------- class MyApp(wx.App): """ ... """ def OnInit(self): #------------ frame = MyFrame(None, title="Sample_three", size=(380, 580)) self.SetTopWindow(frame) frame.Show(True) return True #--------------------------------------------------------------------------- def main(): app = MyApp(False) app.MainLoop() #--------------------------------------------------------------------------- if __name__ == "__main__" : main() }}} -------- == Sample four == {{attachment:img_sample_four.png}} {{{#!python # sample_four.py import wx # class MyPanel # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyPanel(wx.Panel): def __init__(self, *args, **kw): wx.Panel.__init__(self, *args, **kw) self.Bind(wx.EVT_PAINT, self.OnPaint) #----------------------------------------------------------------------- def OnPaint(self, event): """ ... """ gc = wx.GraphicsContext.Create(wx.PaintDC(self)) pen = wx.Pen("navy", 2) gc.SetPen(pen) brush = wx.Brush((255,32,32,128)) gc.SetBrush(brush) gc.PushState() path = gc.CreatePath() path.MoveToPoint(50, 50) path.AddLineToPoint(25,25) path.AddLineToPoint(50,25) path.AddLineToPoint(50,50) path.CloseSubpath() gc.DrawPath(path) gc.Scale(2,2) gc.Translate(10,5) gc.DrawPath(path) gc.Translate(50,0) gc.FillPath(path) gc.Translate(0,5) gc.StrokePath(path) gc.Translate(0,5) brush = wx.Brush((32,32,255,128)) gc.SetBrush(brush) gc.FillPath(path) gc.Translate(50,0) gc.DrawPath(path) gc.PopState() points = [ (5.2, 5.9), (50, 50), (35, 50), (25,40), wx.Point2D(20.5,50.9), wx.Point2D(5,25), (5,6) ] gc.Translate(40, 150) # gc.DrawLines(points) gc.Translate(75, 0) gc.StrokeLines(points) begin = [ (0,0), (0,10), (0,20), (0,30), (0,40), (0,50), ] end = [ (50,0), (50,10), (50,20), (50,30), (50,40), (50,50), ] # In a floating point coordinate system the center of the # pixel is actually at x+0.5, y+0.5, so with anti-aliasing # turned on we'll get a crisper line by positioning our line # segments at the 0.5 offset. For this test we'll just let # the GC do the translation for us. gc.Translate(0.5, 0.5) pen = wx.Pen("purple", 1) gc.SetPen(pen) gc.Translate(75, 0) gc.StrokeLineSegments(begin, end) gc.Translate(75, 0) gc.Scale(2,2) gc.StrokeLineSegments(begin, end) gc.DrawLines(points) del path #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) #------------ self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) #------------ self.Panel = MyPanel(self) #--------------------------------------------------------------------------- class MyApp(wx.App): """ ... """ def OnInit(self): #------------ frame = MyFrame(None, title="Sample_four", size=(420, 320)) self.SetTopWindow(frame) frame.Show(True) return True #--------------------------------------------------------------------------- def main(): app = MyApp(False) app.MainLoop() #--------------------------------------------------------------------------- if __name__ == "__main__" : main() }}} -------- == Sample five == {{attachment:img_sample_five.png}} {{{#!python # sample_five.py """ ZetCode wxPython tutorial. This program performs set operations on regions. Author : Jan Bodnar Website : zetcode.com link : http://www.zetcode.com/wxpython/gdi/ Last edited : May 2018 -------- Region operations : Regions can be combined to create more complex shapes. We can use four set operations : union, intersect, substract, xor. The following example shows all four operations in action. -------- In the example, we present six region set operations. region1 = wx.Region(100, 20, 50, 50) region2 = wx.Region(110, 40, 50, 50) region1.Intersect(region2) """ import wx # class MyFrame # class MyApp #--------------------------------------------------------------------------- class MyFrame(wx.Frame): def __init__(self, *args, **kw): super(MyFrame, self).__init__(*args, **kw) #------------ self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetSize((300, 250)) self.SetMinSize((300, 250)) self.SetBackgroundColour("yellow") #------------ # Simplified init method. self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetTitle("Sample_five (regions)") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc.SetPen(wx.Pen('#000000')) dc.DrawRectangle(20, 20, 50, 50) dc.DrawRectangle(30, 40, 50, 50) dc.SetBrush(wx.Brush('#ffffff')) dc.DrawRectangle(100, 20, 50, 50) dc.DrawRectangle(110, 40, 50, 50) region1 = wx.Region(100, 20, 50, 50) region2 = wx.Region(110, 40, 50, 50) region1.Intersect(region2) rect = region1.GetBox() dc.SetDeviceClippingRegion(region1) dc.SetBrush(wx.Brush('#ff0000')) dc.DrawRectangle(rect) dc.DestroyClippingRegion() dc.SetBrush(wx.Brush('#ffffff')) dc.DrawRectangle(180, 20, 50, 50) dc.DrawRectangle(190, 40, 50, 50) region1 = wx.Region(180, 20, 50, 50) region2 = wx.Region(190, 40, 50, 50) region1.Union(region2) dc.SetDeviceClippingRegion(region1) rect = region1.GetBox() dc.SetBrush(wx.Brush('#fa8e00')) dc.DrawRectangle(rect) dc.DestroyClippingRegion() dc.SetBrush(wx.Brush('#ffffff')) dc.DrawRectangle(20, 120, 50, 50) dc.DrawRectangle(30, 140, 50, 50) region1 = wx.Region(20, 120, 50, 50) region2 = wx.Region(30, 140, 50, 50) region1.Xor(region2) rect = region1.GetBox() dc.SetDeviceClippingRegion(region1) dc.SetBrush(wx.Brush('#619e1b')) dc.DrawRectangle(rect) dc.DestroyClippingRegion() dc.SetBrush(wx.Brush('#ffffff')) dc.DrawRectangle(100, 120, 50, 50) dc.DrawRectangle(110, 140, 50, 50) region1 = wx.Region(100, 120, 50, 50) region2 = wx.Region(110, 140, 50, 50) region1.Subtract(region2) rect = region1.GetBox() dc.SetDeviceClippingRegion(region1) dc.SetBrush(wx.Brush('#715b33')) dc.DrawRectangle(rect) dc.DestroyClippingRegion() dc.SetBrush(wx.Brush('#ffffff')) dc.DrawRectangle(180, 120, 50, 50) dc.DrawRectangle(190, 140, 50, 50) region1 = wx.Region(180, 120, 50, 50) region2 = wx.Region(190, 140, 50, 50) region2.Subtract(region1) rect = region2.GetBox() dc.SetDeviceClippingRegion(region2) dc.SetBrush(wx.Brush('#0d0060')) dc.DrawRectangle(rect) dc.DestroyClippingRegion() #--------------------------------------------------------------------------- class MyApp(wx.App): def OnInit(self): #------------ frame = MyFrame(None) self.SetTopWindow(frame) frame.Show(True) return True #--------------------------------------------------------------------------- def main(): app = MyApp(False) app.MainLoop() #--------------------------------------------------------------------------- if __name__ == "__main__" : main() }}} -------- == Sample six == {{attachment:img_sample_six.png}} {{{#!python # sample_six.py """ ZetCode wxPython tutorial. This program draws uses different joins and caps in drawing. Author : Jan Bodnar Website : zetcode.com Last edited : May 2018 Link : http://zetcode.com/wxpython/gdi/ """ import wx # class Example # def main #--------------------------------------------------------------------------- class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetTitle("Sample_six (joins and caps)") self.SetSize((350, 310)) self.SetMinSize((350, 310)) self.SetBackgroundColour("#8de578") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc = wx.GCDC(dc) pen = wx.Pen('#4c4c4c', 10, wx.SOLID) pen.SetJoin(wx.JOIN_MITER) dc.SetPen(pen) dc.DrawRectangle(15, 15, 80, 50) pen.SetJoin(wx.JOIN_BEVEL) dc.SetPen(pen) dc.DrawRectangle(125, 15, 80, 50) pen.SetJoin(wx.JOIN_ROUND) dc.SetPen(pen) dc.DrawRectangle(235, 15, 80, 50) pen.SetCap(wx.CAP_BUTT) dc.SetPen(pen) dc.DrawLine(30, 150, 150, 150) pen.SetCap(wx.CAP_PROJECTING) dc.SetPen(pen) dc.DrawLine(30, 190, 150, 190) pen.SetCap(wx.CAP_ROUND) dc.SetPen(pen) dc.DrawLine(30, 230, 150, 230) pen2 = wx.Pen('gray', 1, wx.SOLID) dc.SetPen(pen2) dc.DrawLine(30, 130, 30, 250) dc.DrawLine(150, 130, 150, 250) dc.DrawLine(155, 130, 155, 250) #--------------------------------------------------------------------------- def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() #--------------------------------------------------------------------------- if __name__ == '__main__': main() }}} -------- == Sample seven == {{attachment:img_sample_seven.png}} {{{#!python # sample_seven.py """ ZetCode wxPython tutorial. This program draws six rectangles with different pens. Author : Jan Bodnar Website : zetcode.com Last edited : May 2018 Link : http://zetcode.com/wxpython/gdi/ """ import wx # class Example # def main #--------------------------------------------------------------------------- class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetTitle("Sample_seven (pens)") self.SetSize((370, 310)) self.SetMinSize((370, 310)) self.SetBackgroundColour("#e1e0d9") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc = wx.GCDC(dc) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.SOLID)) dc.DrawRectangle(10, 15, 90, 60) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.DOT)) dc.DrawRectangle(130, 15, 90, 60) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.LONG_DASH)) dc.DrawRectangle(250, 15, 90, 60) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.SHORT_DASH)) dc.DrawRectangle(10, 105, 90, 60) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.DOT_DASH)) dc.DrawRectangle(130, 105, 90, 60) dc.SetPen(wx.Pen('#4c4c4c', 2, wx.TRANSPARENT)) dc.DrawRectangle(250, 105, 90, 60) pen = wx.Pen('#4c4c4c', 2, wx.PENSTYLE_USER_DASH) pen.SetDashes([2, 5, 2, 2]) dc.SetPen(pen) dc.DrawRectangle(10, 195, 90, 60) #--------------------------------------------------------------------------- def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() #--------------------------------------------------------------------------- if __name__ == '__main__': main() }}} -------- == Sample eight == {{attachment:img_sample_eight.png}} {{{#!python # sample_eight.py """ ZetCode wxPython tutorial. This program draws nine coloured rectangles on the window. Author: Jan Bodnar Website: zetcode.com Last edited: May 2018 Link : http://zetcode.com/wxpython/gdi/ """ import wx # class Example # def main #--------------------------------------------------------------------------- class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetTitle("Sample_eight (colours)") self.SetSize((400, 310)) self.SetMinSize((400, 310)) self.SetBackgroundColour("lightgray") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc.SetPen(wx.Pen('#d4d4d4')) dc.SetBrush(wx.Brush('#c56c00')) dc.DrawRectangle(35, 15, 90, 60) dc.SetBrush(wx.Brush('#1ac500')) dc.DrawRectangle(147, 15, 90, 60) dc.SetBrush(wx.Brush('#539e47')) dc.DrawRectangle(259, 15, 90, 60) dc.SetBrush(wx.Brush('#004fc5')) dc.DrawRectangle(35, 105, 90, 60) dc.SetBrush(wx.Brush('#c50024')) dc.DrawRectangle(147, 105, 90, 60) dc.SetBrush(wx.Brush('#9e4757')) dc.DrawRectangle(259, 105, 90, 60) dc.SetBrush(wx.Brush('#5f3b00')) dc.DrawRectangle(35, 195, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c')) dc.DrawRectangle(147, 195, 90, 60) dc.SetBrush(wx.Brush('#785f36')) dc.DrawRectangle(259, 195, 90, 60) #--------------------------------------------------------------------------- def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() #--------------------------------------------------------------------------- if __name__ == '__main__': main() }}} -------- == Sample nine == {{attachment:img_sample_nine.png}} {{{#!python # sample_nine.py """ ZetCode wxPython tutorial. This program draws eight rectangles filled with different brushes. Author: Jan Bodnar Website: zetcode.com Last edited: May 2018 Link : http://zetcode.com/wxpython/gdi/ """ import wx # class Example # def main #--------------------------------------------------------------------------- class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetTitle("Sample_nine (brushes)") self.SetSize((400, 310)) self.SetMinSize((400, 310)) self.SetBackgroundColour("#78c2e5") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc.SetBrush(wx.Brush('#4c4c4c', wx.CROSS_HATCH)) dc.DrawRectangle(35, 15, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.SOLID)) dc.DrawRectangle(147, 15, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.BDIAGONAL_HATCH)) dc.DrawRectangle(259, 15, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.CROSSDIAG_HATCH)) dc.DrawRectangle(35, 105, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.FDIAGONAL_HATCH)) dc.DrawRectangle(147, 105, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.HORIZONTAL_HATCH)) dc.DrawRectangle(259, 105, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.VERTICAL_HATCH)) dc.DrawRectangle(35, 195, 90, 60) dc.SetBrush(wx.Brush('#4c4c4c', wx.TRANSPARENT)) dc.DrawRectangle(147, 195, 90, 60) #--------------------------------------------------------------------------- def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() #--------------------------------------------------------------------------- if __name__ == '__main__': main() }}} -------- == Sample ten == {{attachment:img_sample_ten.png}} {{{#!python # sample_ten.py """ ZetCode wxPython tutorial. This program draws three rectangles with custom brush patterns. Author: Jan Bodnar Website: zetcode.com Last edited: May 2018 Link : http://zetcode.com/wxpython/gdi/ """ import wx # class Example # def main #--------------------------------------------------------------------------- class Example(wx.Frame): def __init__(self, *args, **kw): super(Example, self).__init__(*args, **kw) self.InitUI() #----------------------------------------------------------------------- def InitUI(self): """ ... """ self.Bind(wx.EVT_PAINT, self.OnPaint) self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico')) self.SetTitle("Sample_ten (custom patterns)") self.SetSize((400, 140)) self.SetMinSize((400, 140)) self.SetBackgroundColour("white") self.Centre() def OnPaint(self, event): """ ... """ dc = wx.PaintDC(self) dc.SetPen(wx.Pen('#C7C3C3')) brush1 = wx.Brush(wx.Bitmap('./Bitmaps/pattern1.png')) dc.SetBrush(brush1) dc.DrawRectangle(35, 15, 90, 60) brush2 = wx.Brush(wx.Bitmap('./Bitmaps/pattern2.png')) dc.SetBrush(brush2) dc.DrawRectangle(147, 15, 90, 60) brush3 = wx.Brush(wx.Bitmap('./Bitmaps/pattern3.png')) dc.SetBrush(brush3) dc.DrawRectangle(259, 15, 90, 60) #--------------------------------------------------------------------------- def main(): app = wx.App() ex = Example(None) ex.Show() app.MainLoop() #--------------------------------------------------------------------------- if __name__ == '__main__': main() }}} -------- = Download source = [[attachment:source.zip]] -------- = Additional Information = '''Link :''' http://zetcode.com/wxpython/gdi/ - - - - - https://wiki.wxpython.org/TitleIndex https://docs.wxpython.org/ -------- = Thanks to = Cody Precord (sample_four.py coding), Jan Bodnar (sample_five / six / seven / eight / nine / ten.py coding), Chris Barker, the wxPython community... -------- = About this page = Date(d/m/y) Person (bot) Comments : 11/01/20 - Ecco (Created page for wxPython Phoenix). -------- = Comments = - blah, blah, blah...