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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:14:34+00:00 2026-05-27T08:14:34+00:00

I’m creating a StaticText element with multiple child StaticText elements that aren’t quite sizing

  • 0

I’m creating a StaticText element with multiple child StaticText elements that aren’t quite sizing correctly. I’m sure it’s a BoxSizer issue, but maybe not? Here’s a screenshot of what’s happening: http://cloud.smallparade.com/CMxC

That should read:

Wilco
One Sunday Morning (Song
For Jane Smiley's Boyfriend)
The Whole Love (Deluxe Edition)

As you can likely deduce, the second and third lines (Album) are one StaticText element that’s wrapping but not expanding to fit its contents.

Here is the code that creates this element:

def PlayLabel(self, artist, track, album):
    header_font = wx.Font(26, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Helvetica")
    album_font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Helvetica")

    # label container
    block = wx.StaticText(self.Sidebar, -1, '')

    block.sizer = wx.BoxSizer(wx.VERTICAL)
    block.SetBackgroundColour('WHITE')

    label_artist = wx.StaticText(block, -1, artist)
    label_artist.SetForegroundColour('BLACK')
    label_artist.SetFont(header_font)

    label_track = wx.StaticText(block, -1, track)
    label_track.SetForegroundColour('BLACK')
    label_track.SetFont(header_font)

    label_album = wx.StaticText(block, -1, album)
    label_album.SetForegroundColour('BLACK')
    label_album.SetFont(album_font)

    block.sizer.AddMany([
        (label_artist, 1, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, 5),
        (label_track, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5),
        (label_album, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, 5)
    ])
    block.SetSizerAndFit(block.sizer)

    self.Sidebar.sizer.Add(block, 0, wx.EXPAND|wx.ALIGN_LEFT|wx.BOTTOM, 5)
    self.Sidebar.sizer.Layout()
    self.Layout()
    return block

Any idea what’s going on?

EDIT:

Complete code: http://pastie.org/2976327

  • 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-27T08:14:35+00:00Added an answer on May 27, 2026 at 8:14 am

    I’ve never seen anyone create a sizer like that. Normally you do this:

    mySizer = wx.BoxSizer(wx.VERTICAL)
    

    Then you add each element. I suspect that since you’re doing it in a weird way, you’re getting weird results. Don’t use the StaticText’s sizer method for this. They are not container objects. Instead, do this:

    block = wx.BoxSizer(wx.VERTICAL)
    

    And then add the other widgets as you did before. And telling the sizer to set itself won’t work right either: “block.SetSizerAndFit(block.sizer)”. You need to call the parent widget’s SetSizer() method, which is probably the Sidebar here:

    self.Sidebar.SetSizer(block)
    

    or maybe you can just add it the way you had it here:

    self.Sidebar.sizer.Add(block, 0, wx.EXPAND|wx.ALIGN_LEFT|wx.BOTTOM, 5)
    

    EDIT

    Here’s a simple code example:

    import wx
    
    ########################################################################
    class MyFrame(wx.Frame):
        """"""
    
        #----------------------------------------------------------------------
        def __init__(self):
            """Constructor"""
            wx.Frame.__init__(self, None, title="Test")
    
            self.panel = wx.Panel(self)
            self.mainSizer = wx.BoxSizer(wx.VERTICAL)
            samples = [("Red", "Breathe Into Me", "End of Silence"),
                       ("eleventyseven", "Lonely", "Sugarfist"),
                       ("Lecrae", "Go Hard", "Rebel")]
            for sample in samples:
                artist, track, album = sample
                self.PlayLabel(artist, track, album)
    
            self.panel.SetSizer(self.mainSizer)
            panelSizer = wx.BoxSizer()
            panelSizer.Add(self.panel, 1, wx.EXPAND)
            self.SetSizer(panelSizer)
            self.Fit()
    
    
        def PlayLabel(self, artist, track, album):
            header_font = wx.Font(26, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Helvetica")
            album_font = wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Helvetica")
    
            block = self.panel
    
            # sizer
            sizer = self.mainSizer
    
            # artist
            label_artist = wx.StaticText(block, -1, artist)
            label_artist.SetForegroundColour('BLACK')
            label_artist.SetFont(header_font)
    
            # track
            label_track = wx.StaticText(block, -1, track)
            label_track.SetForegroundColour('BLACK')
            label_track.SetFont(header_font)
    
            # album
            label_album = wx.StaticText(block, -1, album)
            label_album.SetForegroundColour('BLACK')
            label_album.SetFont(album_font)
    
            sizer.AddMany([
                    (label_artist, 1, wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, 5),
                    (label_track, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5),
                    (label_album, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
            ])
    
    if __name__ == "__main__":
        app = wx.App(False)
        frame = MyFrame()
        frame.Show()
        app.MainLoop()
    

    I personally don’t like Fit() much, but in this case, it works for me.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.