Finding right width of TextCtrl

Hello All,

How can I find the right width for a TextCtrl for a givn string.

I've tried:
    # ...
    do = wx.TextDataObject(txt)
    t = wx.TextCtrl(self, -1, txt, size=((do.GetTextLength(), -1))
    sizer.Add(t, 0, wx.EXPAND)
    # ...

but it doesn't seem to work.

Bye.

···

--
------------------------------------------------------------------------
Miki Tebeka <miki.tebeka@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

You're finding the width of the string in characters, but the TextCtrl wants
the width of the string in pixels, if I'm not mistaken.

David

···

-----Original Message-----
From: Miki Tebeka [mailto:miki.tebeka@zoran.com]
Sent: Wednesday, August 31, 2005 9:07 AM
To: wxPython mailing list
Subject: [wxPython-users] Finding right width of TextCtrl

Hello All,

How can I find the right width for a TextCtrl for a givn string.

I've tried:
    # ...
    do = wx.TextDataObject(txt)
    t = wx.TextCtrl(self, -1, txt, size=((do.GetTextLength(), -1))
    sizer.Add(t, 0, wx.EXPAND)
    # ...

but it doesn't seem to work.

Bye.
--
--------------------------------------------------------------
----------
Miki Tebeka <miki.tebeka@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price
of the toys

Hello,
I tried this out, maybe the values are not exact.

(I measured out with a screenshot (only the filled area)
width: 21 (rather accurate)
height: 9

t = wx.TextCtrl(shell, -1, "hallo")

t.GetTextExtent("hallo") delivers:
(22, 13)

···

On Wed, 31 Aug 2005 17:07:24 +0300, Miki Tebeka <miki.tebeka@zoran.com> wrote:

Hello All,

How can I find the right width for a TextCtrl for a givn string.

I've tried:
   # ...
   do = wx.TextDataObject(txt)
   t = wx.TextCtrl(self, -1, txt, size=((do.GetTextLength(), -1))
   sizer.Add(t, 0, wx.EXPAND)
   # ...

but it doesn't seem to work.

Bye.

--
Franz Steinhaeusler

Miki Tebeka wrote:

Hello All,

How can I find the right width for a TextCtrl for a givn string.

I've tried:
    # ...
    do = wx.TextDataObject(txt)
    t = wx.TextCtrl(self, -1, txt, size=((do.GetTextLength(), -1))
    sizer.Add(t, 0, wx.EXPAND)
    # ...

but it doesn't seem to work.

Bye.

You must make a temporary screen DC, then use dc.GetTextExtent()
     dc=wx.ScreenDC()
     #if you have a font ...
     dc.SetFont(font)
     (w,h)=dc.GetTextExtent(txt)

Paul Probert
University of Wisconsin

Hello Franz,

[Miki]

How can I find the right width for a TextCtrl for a givn string.

[Franz]

t = wx.TextCtrl(shell, -1, "hallo")

t.GetTextExtent("hallo") delivers:
(22, 13)

That worked.

Thanks,

···

--
------------------------------------------------------------------------
Miki Tebeka <miki.tebeka@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys