Skip to content
Related Articles
Open in App
Not now

Related Articles

wxPython Static Box

Improve Article
Save Article
Like Article
  • Last Updated : 08 Jul, 2020
Improve Article
Save Article
Like Article

In this article we are going to learn about Static Box in wxPython. A static box is a rectangle drawn around other windows to denote a logical grouping of items.
Note that while the previous versions required that windows appearing inside a static box be created as its siblings (i.e. use the same parent as the static box itself), since wxWidgets 2.9.1 it is also possible to create them as children of wx.StaticBox itself and you are actually encouraged to do it like this if compatibility with the previous versions is not important.

Syntax: wx.StaticBox.StaticBox((parent, id=ID_ANY, label=””, pos=DefaultPosition, size=DefaultSize, style=0, name=StaticBoxNameStr)

Parameters

ParameterInput TypeDescription
parentwx.WindowParent window. Must not be None.
idwx.WindowIDWindow identifier. The value wx.ID_ANY indicates a default value.
labelstringText to be displayed in the static box, the empty string for no label.
poswx.PointWindow position. If wx.DefaultPosition is specified then a default position is chosen.
sizewx.SizeCheckbox size. If wx.DefaultSize is specified then a default size is chosen.
stylelongWindow style. There are no StaticBox-specific styles, but generic ALIGN_LEFT, ALIGN_CENTRE_HORIZONTAL and ALIGN_RIGHT can be used here to change the position of the static box label when using wxGTK
namestringWindow name

Code Example:




import wx
  
  
class FrameUI(wx.Frame):
  
    def __init__(self, parent, title):
        super(FrameUI, self).__init__(parent, title = title, size =(300, 200))
  
        # function for in-frame components
        self.InitUI()
  
    def InitUI(self):
        # parent panel for radio box
        pnl = wx.Panel(self)
  
  
        # create static box
        self.sb = wx.StaticBox(pnl, 2, label ="Static Box",
                             pos =(20, 20), size =(100, 100))
  
        # set frame in centre
        self.Centre()
        # set size of frame
        self.SetSize((400, 250))
        # show output frame
        self.Show(True)
  
  
  
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')
ex.MainLoop()

Output Window:


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!