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 6960055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:21:10+00:00 2026-05-27T15:21:10+00:00

It seems to me that the following code should display text right in the

  • 0

It seems to me that the following code should display text right in the centre of the window; that is, in the centre of the inner panel. It doesn’t however, and I’m wondering why not. If you run the code, you’ll see a white panel in the middle of the frame, 150px by 150px. I do not want this area to change in size at all, but when I go about adding some text (uncommenting the txt variable in the middle of the snippet)the panel invariably shrinks to fit the text. Even specifying the size of the StaticText to match the panel isn’t a solution because the text doesn’t then centre-align.

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)




        self.rootPanel = wx.Panel(self)

        innerPanel = wx.Panel(self.rootPanel,-1, size=(150,150), style=wx.ALIGN_CENTER)
        innerPanel.SetBackgroundColour('WHITE')
        hbox = wx.BoxSizer(wx.HORIZONTAL) 
        vbox = wx.BoxSizer(wx.VERTICAL)

        # I want this line visible in the CENTRE of the inner panel
        #txt = wx.StaticText(innerPanel, id=-1, label="TEXT HERE",style=wx.ALIGN_CENTER, name="")

        hbox.Add(innerPanel, 0, wx.ALL|wx.ALIGN_CENTER)
        vbox.Add(hbox, 1, wx.ALL|wx.ALIGN_CENTER, 5)

        self.rootPanel.SetSizer(vbox)
        vbox.Fit(self)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'wxBoxSizer.py')
        frame.Show(True)
        frame.Center()
        return True

app = MyApp(0)
app.MainLoop()
  • 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-27T15:21:11+00:00Added an answer on May 27, 2026 at 3:21 pm

    You just need to add a couple spacers to make it work.

    import wx
    
    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title):
            wx.Frame.__init__(self, parent, id, title)
    
            self.rootPanel = wx.Panel(self)
    
            innerPanel = wx.Panel(self.rootPanel,-1, size=(150,150), style=wx.ALIGN_CENTER)
            innerPanel.SetBackgroundColour('WHITE')
            hbox = wx.BoxSizer(wx.HORIZONTAL) 
            vbox = wx.BoxSizer(wx.VERTICAL)
            innerBox = wx.BoxSizer(wx.VERTICAL)
    
            # I want this line visible in the CENTRE of the inner panel
            txt = wx.StaticText(innerPanel, id=-1, label="TEXT HERE",style=wx.ALIGN_CENTER, name="")
            innerBox.AddSpacer((150,75))
            innerBox.Add(txt, 0, wx.CENTER)
            innerBox.AddSpacer((150,75))
            innerPanel.SetSizer(innerBox)
    
            hbox.Add(innerPanel, 0, wx.ALL|wx.ALIGN_CENTER)
            vbox.Add(hbox, 1, wx.ALL|wx.ALIGN_CENTER, 5)
    
            self.rootPanel.SetSizer(vbox)
            vbox.Fit(self)
    
    class MyApp(wx.App):
        def OnInit(self):
            frame = MyFrame(None, -1, 'wxBoxSizer.py')
            frame.Show(True)
            frame.Center()
            return True
    
    app = MyApp(0)
    app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that seems like it should set my insertParameter but
I have the following code that should display some information about ContactLists in a
It seems that the following piece of HTML is ignored in IE7 but works
It seems that the following is a common method given in many tutorials on
it seems that Markdown.NET does not escape the following: <script> which is kind of
I can't believe that the following statement seems to be still true So, I
I have the following html code: <div class=outer ui-draggable style=position: relative;> <div class=inner>Foo bar</div>
I have an issue with the following text display: <asp:RegularExpressionValidator ID=Password_RegularExpValidate runat=server Text=TEST! Display=Dynamic
Really simple question: Am I missing something? Seems like this should be all that
Shouldn't a browser's textarea display raw text? Look at the following snaps from this

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.