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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:08:37+00:00 2026-06-10T10:08:37+00:00

I have a panel containing a button as well as another panel which itself

  • 0

I have a panel containing a button as well as another panel which itself contains a textCtrl. I have a panel just for the textctrl because I am trying to have a custom border color around the textCtrl. Unfortunately I can not get the textCtrl to not fill the entire panel..I suspect it has to do with the SetSizerAndFit but I am not sure. Is it possible to have a custom colored border around the textCtrl ?
Here’s the code:

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

        wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(800,600))

    self.panel=wx.Panel(self,wx.ID_ANY,style=wx.BORDER_SIMPLE)
    self.panelText=wx.Panel(self.panel,wx.ID_ANY,
        size=(450,40),style=wx.BORDER_SIMPLE)

    self.panel.SetBackgroundColour("white")
    self.panelText.SetBackgroundColour("#27bbdc")

    size=self.panelText.GetSize()

    self.sizerControls=wx.BoxSizer(wx.HORIZONTAL)
    self.sizerMain=wx.BoxSizer(wx.VERTICAL)
    #self.sizerText=wx.BoxSizer(wx.HORIZONTAL)

    #-------------Objects------------
    self.text=wx.TextCtrl(self.panelText,-1, style=wx.TE_READONLY|wx.NO_BORDER,
        size=(size[0]-4,size[1]-4),pos=(1,1))
    image=wx.Image("Button_80x80.png",wx.BITMAP_TYPE_ANY).ConvertToBitmap()
    self.buttonFolder=wx.BitmapButton(self.panel,-1,bitmap=image,
        size=(95,95),style=wx.NO_BORDER)        

    #-------------Sizers-------------
    #self.sizerText.Add((0,0),1)
    #self.sizerText.Add(self.text,0,flag=wx.ALIGN_CENTER)
    #self.sizerText.Add((0,0),1)
    self.sizerControls.Add(self.panelText,1,flag=wx.ALIGN_CENTER)
    self.sizerControls.Add(self.buttonFolder,0,flag=wx.ALIGN_CENTER)
    self.sizerMain.Add(self.sizerControls,1,flag=wx.ALIGN_CENTER)

    #-------------Events-------------
    self.Bind(wx.EVT_BUTTON, self.OnButton, self.buttonFolder)

    self.panel.SetSizerAndFit(self.sizerMain)

    self.Show()
  • 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-06-10T10:08:38+00:00Added an answer on June 10, 2026 at 10:08 am

    Your problem is that the wx.TextCtrl is not centered in the panel. This is because you’re setting the position to (1,1) (i.e. 1 pixel below and to the right of the top left corner)

    I ran your code (commenting out the code relating to the wx.BitmapButton since I didn’t have the file). If you increase the panel difference from 4 pixels to 10 pixels you see this:

    10 pixel border, not centered

    Notice how all the colour is in the bottom right?

    Mike Driscoll already gave you the answer, but you slightly misunderstood. The point of using the wx.All flag and a sizer wasn’t to create a border that you could set the colour on, it was to center your wx.TextCtrl in the panel and let the colour of the panel show through.

    Look at this code snippet

    self.sizerText=wx.BoxSizer(wx.HORIZONTAL)
    self.text=wx.TextCtrl(self.panelText,-1, style=wx.TE_READONLY|wx.NO_BORDER)
    #dont' set the size nor the position
    self.sizerText.Add(self.text, 1, flag=wx.ALL|wx.EXPAND, border=10)
    #make the textCtrl expand in all possible directions but leave a 10 pixel border on all sides
    #since the border is on left/right and top/bottom this is equivalent to panel size - 20
    self.panelText.SetSizer(self.sizerText)
    

    Which results in a window like this:
    10 pixel border, centered

    As a side note, as I alluded to in my code, setting the the panel size – 4 equates to only a 2 pixel border, which is hard to see. That may have also been part of your problem.

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

Sidebar

Related Questions

I have a panel containing a panel which contains a panel which contains several
i have a panel (A), which contains 3 other panels (AA, AB, AC). Each
I have a panel containing a number of components, one of which is a
I have a webpage containing a panel and a button. When you click the
I have a somewhat complex custom user control, created in C# .NET, which is
I have a couple of update panels, one containing a gridview and another containing
I have MainWindow containing a datagrid and a filter panel. The filter panel can
I'm trying to make a sidebar which on a website which will have a
I have a UItableView controller containing images. I also have a refresh button to
I have a panel containing a form (elements such as labels and textboxes within

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.