Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between widgets WxPython

This is my code:

class TabTwo(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.resetButton = wx.Button(self, label="Reset")
        self.contactButton = wx.Button(self, label="Contact")
        self.copyrightButton = wx.Button(self, label="Copyright")

        v_sizer = wx.BoxSizer(wx.VERTICAL)
        h_sizer = wx.BoxSizer(wx.HORIZONTAL)

        v_sizer.Add(self.resetButton, 0, wx.EXPAND, 30)
        v_sizer.Add(self.contactButton, 0, wx.EXPAND, 30)
        v_sizer.Add(self.copyrightButton, 0, wx.EXPAND, 30)

        self.SetSizer(v_sizer)

How do I add some space between the buttons (Reset, Contact and Copyright) so that it doesn't look to much like it's been pressed together.
Current layout of the buttons

like image 840
HelloThereToad Avatar asked May 12 '26 04:05

HelloThereToad


1 Answers

Specify a border when adding to the sizer:

    v_sizer.Add( self.resetButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
    v_sizer.Add( self.contactButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
    v_sizer.Add( self.copyrightButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )

Here wx.TOP|wx.BOTTOM specifies to add a border to the top and bottom of the widget. I'm assuming you just want top and bottom; wx.ALL adds on all sides. Also wx.RIGHT and wx.LEFT are available.

The parameter following wx.EXPAND|wx.TOP|wx.BOTTOM (ie 5) is the size of the border.

See here for more information: https://wxpython.org/Phoenix/docs/html/wx.Sizer.html#wx-sizer. In particular the Add function and the flag and border parameters.

like image 188
Jibbity jobby Avatar answered May 14 '26 19:05

Jibbity jobby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!