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

  • Home
  • SEARCH
  • 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 6150701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:39:16+00:00 2026-05-23T19:39:16+00:00

I am currently trying to get a grip on wxPython, and I stumbeled over

  • 0

I am currently trying to get a grip on wxPython, and I stumbeled over nesting sizers, putting them on a panel and fit them.

I want to have a GridBagSizer in a StaticBoxSizer in a BoxSizer. The whole should be on a panel.

My code:

import wx

class App(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Frame", size=(550, 300))
        panel = wx.Panel(self, -1)
        mainSizer = self.makeOuterSizer()

        # fit layout
        panel.SetSizer(mainSizer)
        mainSizer.Fit(panel)

##         mainSizer.Fit(self)
##         self.SetSizer(mainSizer)

    # ----

    def makeOuterSizer(self):

        # define sizer
        innerSizer = self.makeGrid()

        # make 
        outerSizer = wx.BoxSizer(wx.VERTICAL)
        outerSizer.Add(innerSizer, 0, wx.EXPAND|wx.CENTER|wx.ALL, 10)

        return outerSizer
    # ----

    def makeGrid(self):

        sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, ""), wx.VERTICAL)

        # make fields
        itemMonomer1_label = wx.StaticText(self, -1, "Text 1")
        self.itemMonomer1_value = wx.TextCtrl(self, -1, "", size=(100, -1))
        itemMonomer2_label = wx.StaticText(self, -1, "Text 2")
        self.itemMonomer2_value = wx.TextCtrl(self, -1, "", size=(100, -1))
        itemMonomer3_label = wx.StaticText(self, -1, "Text 3")
        self.itemMonomer3_value = wx.TextCtrl(self, -1, "", size=(100, -1))

        # pack elements

        grid = wx.GridBagSizer(2, 3)

        grid.Add(itemMonomer1_label, (0,0), flag=wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL)
        grid.Add(self.itemMonomer1_value, (1,0), flag=wx.EXPAND)
        grid.Add(itemMonomer2_label, (0,1), flag=wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL)
        grid.Add(self.itemMonomer2_value, (1,1), flag=wx.EXPAND)
        grid.Add(itemMonomer3_label, (0,2), flag=wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL)
        grid.Add(self.itemMonomer3_value, (1,2), flag=wx.EXPAND)

        sizer.Add(grid, 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 5)

        return sizer
    # ----

if __name__ == '__main__':
    app = wx.App()
    App().Show(True)
    app.MainLoop()

So, the code above does not really work. However, when I quote lines 10 and 11, and unquote lines 13 and 14, at least the GridBagSizer is correctly shown. So I suspect that something in my SetSizer and Fit lines must be wrong… But the panel is still stuck in the upper right corner and does not work…

Any hint is much apprechiated!

Thanks, Woodpicker

  • 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-23T19:39:16+00:00Added an answer on May 23, 2026 at 7:39 pm

    The widgets you want to display on the panel should be children of the panel instead of the frame. Try the following changes:

    class App(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, "Frame", size=(550, 300))
            self.panel = wx.Panel(self, -1)
            mainSizer = self.makeOuterSizer()
    
            # fit layout
            self.panel.SetSizer(mainSizer)
            mainSizer.Fit(self.panel)
    
    # ...
    
    def makeGrid(self):
    
        sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, -1, ""), wx.VERTICAL)
    
        # make fields
        itemMonomer1_label = wx.StaticText(self.panel, -1, "Text 1")
        self.itemMonomer1_value = wx.TextCtrl(self.panel, -1, "", size=(100, -1))
        itemMonomer2_label = wx.StaticText(self.panel, -1, "Text 2")
        self.itemMonomer2_value = wx.TextCtrl(self.panel, -1, "", size=(100, -1))
        itemMonomer3_label = wx.StaticText(self.panel, -1, "Text 3")
        self.itemMonomer3_value = wx.TextCtrl(self.panel, -1, "", size=(100, -1))
    

    You will still have to give the GridBagSizer one or more growable columns if you want it to expand along with the StaticBox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get a grip on Android development and working my way
I am currently trying to get my UI to have a Title Bar, a
I'm currently trying to get a grip on SVN and how to handle projects
I'm currently trying to get my head wrap around Cassandra/thrift with Erlang... I have
I'm currently trying to get to grips with AJAX, and have a problem accessing
I'm currently trying to get a Tomcat server I have running in Eclipse on
Maybe I have a bad design but I am currently trying to get an
Im currently trying to get used to assembler and I have written a for
I'm currently trying to get the most popular productID from my MSSQL Database. This
I am currently trying to get my app to run on my iPhone 4.

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.