How to create a rounded rectangle (Phoenix)

Keywords : RoundedRectangle, Drawing, PaintDC, GCDC.


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


First example

img_sample_one.png

   1 # sample_one.py
   2 
   3 import wx
   4 
   5 # class MyPanel
   6 # class MyFrame
   7 # class MyApp
   8 
   9 #---------------------------------------------------------------------------
  10 
  11 class MyPanel(wx.Panel):
  12     def __init__(self, *args, **kwargs):
  13         wx.Panel.__init__(self, *args, **kwargs)
  14 
  15         self.Bind(wx.EVT_PAINT, self.OnPaint)
  16 
  17     #-----------------------------------------------------------------------
  18 
  19     def OnPaint(self, event):
  20         """
  21         ...
  22         """
  23 
  24         pdc = wx.PaintDC(self)
  25         gc = wx.GCDC(pdc)
  26         gc.Clear()
  27 
  28         gc.SetPen(wx.Pen("black", 2))
  29         gc.SetBrush(wx.YELLOW_BRUSH)
  30 
  31         x = 100
  32         y = 30
  33         w = 100
  34         h = 50
  35 
  36         for radius in [3, 6, 9, 12, 15, 18, 21]:
  37             # x, y , width, height, radius
  38             gc.DrawRoundedRectangle(x, y, w, h, radius)
  39             gc.DrawText(str(radius), int(x+w+10), int(y+h/2))
  40             y+=100
  41 
  42 #---------------------------------------------------------------------------
  43 
  44 class MyFrame(wx.Frame):
  45     def __init__(self, *args, **kwargs):
  46         wx.Frame.__init__(self, *args, **kwargs)
  47 
  48         #------------
  49 
  50         frameicon = wx.Icon("icon_wxWidgets.ico")
  51         self.SetIcon(frameicon)
  52 
  53         #------------
  54 
  55         self.Panel = MyPanel(self)
  56 
  57 #---------------------------------------------------------------------------
  58 
  59 class MyApp(wx.App):
  60     """
  61     ...
  62     """
  63     def OnInit(self):
  64 
  65         #------------
  66 
  67         frame = MyFrame(None, title="Sample_one", size=(320, 750))
  68         self.SetTopWindow(frame)
  69         frame.Show(True)
  70 
  71         return True
  72 
  73 #---------------------------------------------------------------------------
  74 
  75 def main():
  76     app = MyApp(False)
  77     app.MainLoop()
  78 
  79 #---------------------------------------------------------------------------
  80 
  81 if __name__ == "__main__" :
  82     main()


Download source

source.zip


Additional Information

Link :

http://zetcode.com/wxpython/gdi/

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Chris Barker, the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

14/12/19 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a rounded rectangle (Phoenix) (last edited 2020-12-17 17:06:59 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.