Anchoring buttons to container edges

I’m trying to set two buttons so that one is anchored to the left of the sizer and the other to the right. I tried using wx.lib.anchors.LayoutAnchors as follows:

from wx.lib.anchors import LayoutAnchors
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)

self.btnSave = wx.Button(self.panel_1, wx.ID_ANY, "Save")
self.btnSave.SetToolTip("Save comment and close")
self.btnSave.SetConstraints(LayoutAnchors(self.btnSave, left=1, top=0, right=0, bottom=0))
sizer_2.Add(self.btnSave, 0, 0, 0)

self.btnIMDB = wx.Button(self.panel_1, wx.ID_ANY, "IMDB")
self.btnIMDB.SetToolTip("Fetch info from IMDB")
self.btnIMDB.SetConstraints(LayoutAnchors(self.btnIMDB, left=0, top=0, right=1, bottom=0))
sizer_2.Add(self.btnIMDB, 0, 0, 0)

but I just get two buttons jammed together on the left edge. After looking at the example in wxDemo I came to the conclusion that what actually happens is that anchoring to the right just maintains its original distance from the right edge on resize. It does not (like vb.NET) “glue” it to the right edge. But when I resized my panel the IMDB button, alas, remained glued to the Save button so that assumption was also incorrect. Is there a simple way to say I want the IMDB button “stuck” to the right edge?

Perhaps you could add a spacer between the buttons with its proportion set to 1.

import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 100))

        self.panel_1 = wx.Panel(self, wx.ID_ANY)

        sizer_1 = wx.BoxSizer(wx.VERTICAL)

        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_1.Add(sizer_2, 0, wx.EXPAND, 0)

        self.button_1 = wx.Button(self.panel_1, wx.ID_ANY, "button_1")
        sizer_2.Add(self.button_1, 0, 0, 0)

        sizer_2.Add((20, 20), 1, 0, 0)

        self.button_2 = wx.Button(self.panel_1, wx.ID_ANY, "button_2")
        sizer_2.Add(self.button_2, 0, 0, 0)



class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        return True

if __name__ == "__main__":
    app = MyApp(0)


Apparently I am overthinking this. I’ve done a fair bit of work in and I was stuck on “anchor”.