Search code examples
wxpythonwxwidgets

Spacing/empty border for wxWidgets


Is there anything you can use to add space around the edges of a window or between components with wxWidgets/wxPython? I want something to prevent components from being squished up against the window border or each other, similar to what can be done with Java Swing's EmptyBorder or Insets. (I know you can set horizontal/vertical gaps with some sizers, but I'd like something more flexible.)


Solution

  • See the border parameter in the Sizer's Add method. You can use the flag parameter to tell it where to put the border, such as wx.ALL, wx.RIGHT, wx.LEFT, wx.TOP, etc.

    This can be used to put space around widgets and between widgets. Sometimes you might want to use the sizer's AddSpacer to add space. Or you can just do something like this:

    mySizer.Add((20, 100))
    

    What that does is put 100 pixels between two widgets on the y axis. You'll probably have to play with it a bit to get it the way you want.

    See also http://wiki.wxpython.org/GridSizerTutorial or http://zetcode.com/wxpython/layout/