How to create a flex grid sizer (Phoenix)

Keywords : Flex grid sizer.


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

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 https://maku77.github.io/python/wxpython/layout.html
   6 
   7 """
   8 
   9 import wx
  10 
  11 # class MyFrame
  12 
  13 #---------------------------------------------------------------------------
  14 
  15 class MyFrame(wx.Frame):
  16     def __init__(self):
  17         wx.Frame.__init__(self, None, -1,
  18                           "wx.FlexGridSizer", size=(300, 150))
  19 
  20         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  21 
  22         #------------
  23 
  24         self.InitializeComponents()
  25 
  26     #-----------------------------------------------------------------------
  27 
  28     def InitializeComponents(self):
  29         mainPanel = wx.Panel(self)
  30 
  31         button1 = wx.Button(mainPanel, -1, "Button 1")
  32         button2 = wx.Button(mainPanel, -1, "Button 2")
  33         button3 = wx.Button(mainPanel, -1, "Button 3")
  34         button4 = wx.Button(mainPanel, -1, "Button 4")
  35         button5 = wx.Button(mainPanel, -1, "Button 5")
  36         button6 = wx.Button(mainPanel, -1, "Button 6")
  37 
  38         #------------
  39 
  40         # Create a sizer.
  41         sizer = wx.FlexGridSizer(2, 3, (0, 0))
  42 
  43         sizer.Add(button1, flag=wx.EXPAND)
  44         sizer.Add(button2, flag=wx.EXPAND)
  45         sizer.Add(button3, flag=wx.EXPAND)
  46         sizer.Add(button4, flag=wx.EXPAND)
  47         sizer.Add(button5, flag=wx.EXPAND)
  48         sizer.Add(button6, flag=wx.EXPAND)
  49 
  50         mainPanel.SetSizer(sizer)
  51 
  52 #---------------------------------------------------------------------------
  53 
  54 if __name__ == '__main__':
  55     app = wx.App()
  56     MyFrame().Show(True)
  57     app.MainLoop()


Sample two

img_sample_two.png

   1 # sample_two.py
   2 
   3 """
   4 
   5 https://maku77.github.io/python/wxpython/layout.html
   6 
   7 """
   8 
   9 import wx
  10 
  11 # class MyFrame
  12 
  13 #---------------------------------------------------------------------------
  14 
  15 class MyFrame(wx.Frame):
  16     def __init__(self):
  17         wx.Frame.__init__(self, None, -1,
  18                           "wx.FlexGridSizer (proportion)", size=(450, 150))
  19 
  20         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  21 
  22         #------------
  23 
  24         self.InitializeComponents()
  25 
  26     #-----------------------------------------------------------------------
  27 
  28     def InitializeComponents(self):
  29         mainPanel = wx.Panel(self)
  30 
  31         button1 = wx.Button(mainPanel, -1, "Button 1")
  32         button2 = wx.Button(mainPanel, -1, "Button 2")
  33         button3 = wx.Button(mainPanel, -1, "Button 3")
  34         button4 = wx.Button(mainPanel, -1, "Button 4")
  35         button5 = wx.Button(mainPanel, -1, "Button 5")
  36         button6 = wx.Button(mainPanel, -1, "Button 6")
  37 
  38         #------------
  39 
  40         # Create a sizer.
  41         sizer = wx.FlexGridSizer(2, 3, (0, 0))
  42 
  43         sizer.Add(button1, flag=wx.EXPAND)
  44         sizer.Add(button2, flag=wx.EXPAND)
  45         sizer.Add(button3, flag=wx.EXPAND)
  46         sizer.Add(button4, flag=wx.EXPAND)
  47         sizer.Add(button5, flag=wx.EXPAND)
  48         sizer.Add(button6, flag=wx.EXPAND)
  49 
  50         sizer.AddGrowableRow(0, 1)
  51         sizer.AddGrowableRow(1, 2)
  52         sizer.AddGrowableCol(0, 1)
  53         sizer.AddGrowableCol(1, 3)
  54         sizer.AddGrowableCol(2, 1)
  55 
  56         mainPanel.SetSizer(sizer)
  57 
  58 #---------------------------------------------------------------------------
  59 
  60 if __name__ == '__main__':
  61     app = wx.App()
  62     MyFrame().Show(True)
  63     app.MainLoop()


Sample three

img_sample_three.png

   1 # sample_three.py
   2 
   3 """
   4 
   5 https://maku77.github.io/python/wxpython/layout.html
   6 
   7 """
   8 
   9 import wx
  10 
  11 # class MyFrame
  12 
  13 #---------------------------------------------------------------------------
  14 
  15 class MyFrame(wx.Frame):
  16     def __init__(self):
  17         wx.Frame.__init__(self, None, -1,
  18                           "wx.FlexGridSizer (AddGrowableRow)", size=(450, 150))
  19 
  20         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  21 
  22         #------------
  23 
  24         self.InitializeComponents()
  25 
  26     #-----------------------------------------------------------------------
  27 
  28     def InitializeComponents(self):
  29         mainPanel = wx.Panel(self)
  30 
  31         button1 = wx.Button(mainPanel, -1, "Button 1")
  32         button2 = wx.Button(mainPanel, -1, "Button 2")
  33         button3 = wx.Button(mainPanel, -1, "Button 3")
  34         button4 = wx.Button(mainPanel, -1, "Button 4")
  35         button5 = wx.Button(mainPanel, -1, "Button 5")
  36         button6 = wx.Button(mainPanel, -1, "Button 6")
  37 
  38         #------------
  39 
  40         # Create a sizer.
  41         sizer = wx.FlexGridSizer(2, 3, (0, 0))
  42 
  43         sizer.Add(button1, flag=wx.EXPAND)
  44         sizer.Add(button2, flag=wx.EXPAND)
  45         sizer.Add(button3, flag=wx.EXPAND)
  46         sizer.Add(button4, flag=wx.EXPAND)
  47         sizer.Add(button5, flag=wx.EXPAND)
  48         sizer.Add(button6, flag=wx.EXPAND)
  49 
  50         sizer.AddGrowableRow(0)
  51         sizer.AddGrowableCol(2)
  52 
  53         mainPanel.SetSizer(sizer)
  54 
  55 #---------------------------------------------------------------------------
  56 
  57 if __name__ == '__main__':
  58     app = wx.App()
  59     MyFrame().Show(True)
  60     app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Maku77(sample_one / two / three.py coding), the wxPython community...


About this page

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

15/12/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a flex grid sizer (Phoenix) (last edited 2021-01-07 17:38:19 by Ecco)

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