How to get text size in pixels with selected font and size.

I am thinking of using wxStaticText for that, and getting it’s size, but maybe there is a better way?

The primary method that I’m aware of is using a device context’s GetTextExtent() method. You can see a pretty good example on the wiki here:

http://wiki.wxpython.org/CreatingCustomControls

See lines 43-50 in the 2nd code sample.

  • Mike
···

On Monday, August 18, 2014 8:26:44 AM UTC-5, GamerCat wrote:

I am thinking of using wxStaticText for that, and getting it’s size, but maybe there is a better way?

Thanks, Mike, works like a charm! :slight_smile:

···

On Monday, August 18, 2014 3:45:28 PM UTC+2, Mike Driscoll wrote:

On Monday, August 18, 2014 8:26:44 AM UTC-5, GamerCat wrote:

I am thinking of using wxStaticText for that, and getting it’s size, but maybe there is a better way?

The primary method that I’m aware of is using a device context’s GetTextExtent() method. You can see a pretty good example on the wiki here:

http://wiki.wxpython.org/CreatingCustomControls

See lines 43-50 in the 2nd code sample.

  • Mike