Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1108691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:07:27+00:00 2026-05-17T02:07:27+00:00

Ok I have an application I am coding and am trying to get a

  • 0

Ok I have an application I am coding and am trying to get a layout simpler to this:
Sizer Alignment with all the input boxes aligned

Notice how the text is left justified and the input boxes are all aligned, I see this in the wxPython demo code, but they all use the flexgrid sizer and I am trying to only use BoxSizers (due to them being simpler and because I only understand a little of sizers and even struggle with using BoxSizers, in 6 months I would have an even harder time)

I have tried having the input and text in two vertical sizers and then putting those in a horizontal sizer, didn’t work because the text was not aligned with the inputs. I also tried doing that and also having each text, input pairing in a sizer, even worse. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:07:27+00:00Added an answer on May 17, 2026 at 2:07 am

    Here’s a simple example using just BoxSizers:

    import wx
    
    class MyForm(wx.Frame):
    
        def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
    
            # Add a panel so it looks the correct on all platforms
            panel = wx.Panel(self, wx.ID_ANY)
    
            # create the labels
            lblOne = wx.StaticText(panel, label="labelOne", size=(60,-1))
            lblTwo = wx.StaticText(panel, label="lblTwo", size=(60,-1))
            lblThree = wx.StaticText(panel, label="lblThree", size=(60,-1))
    
            # create the text controls
            txtOne = wx.TextCtrl(panel)
            txtTwo = wx.TextCtrl(panel)
            txtThree = wx.TextCtrl(panel)
    
            # create some sizers
            mainSizer = wx.BoxSizer(wx.VERTICAL)
            lineOneSizer = wx.BoxSizer(wx.HORIZONTAL)
            lineTwoSizer = wx.BoxSizer(wx.HORIZONTAL)
            lineThreeSizer = wx.BoxSizer(wx.HORIZONTAL)
    
            # add widgets to sizers
            lineOneSizer.Add(lblOne, 0, wx.ALL|wx.ALIGN_LEFT, 5)
            lineOneSizer.Add(txtOne, 0, wx.ALL, 5)
            lineTwoSizer.Add(lblTwo, 0, wx.ALL|wx.ALIGN_LEFT, 5)
            lineTwoSizer.Add(txtTwo, 0, wx.ALL, 5)
            lineThreeSizer.Add(lblThree, 0, wx.ALL|wx.ALIGN_LEFT, 5)
            lineThreeSizer.Add(txtThree, 0, wx.ALL, 5)
    
            mainSizer.Add(lineOneSizer)
            mainSizer.Add(lineTwoSizer)
            mainSizer.Add(lineThreeSizer)
    
            panel.SetSizer(mainSizer)
    
    # Run the program
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyForm()
        frame.Show()
        app.MainLoop()
    

    But this is kind of messy, so here’s a refactored version:

    import wx
    
    class MyForm(wx.Frame):
    
        def __init__(self):
            wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
    
            # create the main sizer
            self.mainSizer = wx.BoxSizer(wx.VERTICAL)
    
            # Add a panel so it looks the correct on all platforms
            self.panel = wx.Panel(self, wx.ID_ANY)
    
            lbls = ["labelOne", "lblTwo", "lblThree"]
            for lbl in lbls:
                self.buildLayout(lbl)
            self.panel.SetSizer(self.mainSizer)
    
        #----------------------------------------------------------------------
        def buildLayout(self, text):
            """"""
            lblSize = (60,-1)
            lbl = wx.StaticText(self.panel, label=text, size=lblSize)
            txt = wx.TextCtrl(self.panel)
    
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.Add(lbl, 0, wx.ALL|wx.ALIGN_LEFT, 5)
            sizer.Add(txt, 0, wx.ALL, 5)
            self.mainSizer.Add(sizer)
    
    # Run the program
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyForm()
        frame.Show()
        app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.