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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:32:31+00:00 2026-05-15T07:32:31+00:00

I’m working with wxpython (2.8) with python 2.5. is it possible to force a

  • 0

I’m working with wxpython (2.8) with python 2.5.
is it possible to force a wx.CheckBox to display its label on multiple
lines?
I’d like to be able to do the same as wx.StaticText.Wrap(width)

See the attached example: the wx.CheckBox is 200 px wide, but it’s
label does not fit in this space.

Any help is really appreciated!
Thanks a lot
Mauro

#example starts here

import wx


class MyFrame(wx.Frame):
   def __init__(self):
       wx.Frame.__init__(self,  None, title="Hello World", size=
(300,200))

       self.panel = wx.Panel(self,  -1)
       myVSizer = wx.BoxSizer(wx.VERTICAL)

       #instantiating a checkbox 200 px wide. but the label is too
long
       cb = wx.CheckBox(self.panel,  -1,  label="This is a very very
long label for 200 pixel wide cb!",  size =wx.Size(200, -1))

       myVSizer.Add( cb, 1)

       self.panel.SetSizer(myVSizer)
       myVSizer.Layout()


app = wx.App(redirect=True)
top = MyFrame()
top.Show()
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-15T07:32:32+00:00Added an answer on May 15, 2026 at 7:32 am

    what about something like this? Flex!
    (I’ve made it a radio button to show that it still behaves like one)

    import wx
    import textwrap
    
    class MultilineRadioButton(wx.RadioButton):
            def __init__(self, parent, id=-1, label=wx.EmptyString, wrap=10, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, validator=wx.DefaultValidator, name=wx.RadioButtonNameStr):
                wx.RadioButton.__init__(self,parent,id,'',pos,size,style,validator,name)
                self._label = label
                self._wrap = wrap
                lines = self._label.split('\n')
                self._wrappedLabel = []
                for line in lines:
                    self._wrappedLabel.extend(textwrap.wrap(line,self._wrap))
    
                self._textHOffset = 20
                dc = wx.ClientDC(self)
                font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
                dc.SetFont(font)
                maxWidth = 0
                totalHeight = 0
                lineHeight = 0
                for line in self._wrappedLabel:
                    width, height = dc.GetTextExtent(line)
                    maxWidth = max(maxWidth,width)
                    lineHeight = height
                    totalHeight += lineHeight 
    
                self._textHeight = totalHeight
    
                self.SetInitialSize(wx.Size(self._textHOffset + maxWidth,totalHeight))
                self.Bind(wx.EVT_PAINT, self.OnPaint)
    
            def OnPaint(self, event):
                dc = wx.PaintDC(self)
                self.Draw(dc)
                self.RefreshRect(wx.Rect(0,0,self._textHOffset,self.GetSize().height))
                event.Skip()
    
            def Draw(self, dc):
                dc.Clear()
                font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
                dc.SetFont(font)
                height = self.GetSize().height
                if height > self._textHeight:
                    offset = height / 2 - self._textHeight / 2
                else:
                    offset = 0
                for line in self._wrappedLabel:
                    width, height = dc.GetTextExtent(line)
                    dc.DrawText(line,self._textHOffset,offset)
                    offset += height
    
    
    class HFrame(wx.Frame):
       def __init__(self,pos=wx.DefaultPosition):
           wx.Frame.__init__(self,None,title="Hello World",size=wx.Size(600,400),pos=pos)
    
           self.panel = wx.Panel(self,-1)
           sizer = wx.BoxSizer(wx.HORIZONTAL)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           self.panel.SetSizer(sizer)
           sizer.Layout()
    
    
    class VFrame(wx.Frame):
       def __init__(self,pos=wx.DefaultPosition):
           wx.Frame.__init__(self,None,title="Hello World",size=wx.Size(600,400),pos=pos)
    
           self.panel = wx.Panel(self,-1)
           sizer = wx.BoxSizer(wx.VERTICAL)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           cb = RadioButton(self.panel,-1,label="This is a very very long label for the control!",wrap=10)
           sizer.Add(cb,1)
    
           self.panel.SetSizer(sizer)
           sizer.Layout()
    
    
    app = wx.App(redirect=False)
    htop = HFrame(pos=wx.Point(0,50))
    htop.Show()
    vtop = VFrame(pos=wx.Point(650,50))
    vtop.Show()
    app.MainLoop()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 472k
  • Answers 472k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is that first page allows anonymous access and… May 16, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer Using the extension method described here : Testing t =… May 16, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer Personally I don't like using prefixes - it makes the… May 16, 2026 at 3:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.