How to get the width of a string in pixels?

前端 未结 2 1445
清歌不尽
清歌不尽 2021-01-02 08:24

I am using wxPython\'s HyperTreeList and I want to set the column width exactly equal to length of the largest string in it.

To accomplish that, I\'d like to to conv

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 08:28

    You'll have to do something like (see the documentation of wxWidgets for more info)

    f = window.GetFont()
    dc = wx.WindowDC(window)
    dc.SetFont(f)
    width, height = dc.GetTextExtent("Text to measure")
    

提交回复
热议问题