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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:03:13+00:00 2026-06-17T05:03:13+00:00

I have an application I am developing in wxPython. Part of the application creates

  • 0

I have an application I am developing in wxPython. Part of the application creates a large number of TextCtrls in a grid in order to enter four-letter codes for each day of the week for an arbitrarily large list of people.

I’ve managed to make it work, but I’m having to do something kludgy. Specifically, I haven’t found a good way to figure out how big (in pixels) a bit of text is, so I have to guess at sizing the TextCtrls in order to just fit the biggest (4 letter) code. My concern is that if the size of the text was to change, or the application was ported to something other than MSW, that my layout might break.

The solution I found was to create a StaticText object, fill it with 4 large letters, get its size, and then .Destroy() it. This works, but it really seems like a klunky solution. Does anyone have a more direct method for figuring out just how big an arbitrary text string will be in a TextCtrl? I’ve looked in the docs and haven’t been able to find anything, and I haven’t seen any examples that do precisely what I’m trying to do.

A little code sample (showing the test method) follows:

    # This creates and then immediately destroys a static text control
    # in order to learn how big four characters are in the current font.
    testst = wx.StaticText(self, id = wx.ID_ANY, label = "XXXX")
    self.fourlettertextsize = testst.GetClientSize() + (4,4)
    testst.Destroy()

(The + (4,4) part is to add a little more space in the control to accommodate the cursor and a little border in the client area of the TextCtrl; this is another thing I’d rather not be doing directly.)

  • 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-17T05:03:14+00:00Added an answer on June 17, 2026 at 5:03 am

    Create a wx.Font instance with the face, size, etc.; create a wx.DC; then call dc.GetTextExtent(“a text string”) on that to get the width and height needed to display that string. Set your row height and column width in the grid accordingly.

    Something like:

    font = wx.Font(...)
    dc = wx.DC()
    dc.SetFont(font)
    w,h = dc.GetTextExtent("test string")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I have been developing the application for drawing, and I have the problem: my
I have been developing the application for drawing and I need to detect double
I have been developing the application for drawing, and there is the code: public
I have been developing the application for drawing and I have some problems: the
I have been developing the application, and I need that drawingg is executed in
I have been developing the application for drawing, and there is the following code
I have been developing Android application for Android 3.x and now I want to
I'm developing an iPhone application that have a TabBarController with two tabs. Each tab
I am developing an xbap application and have run into a problem with users

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.