I’m just getting started with wxPython, and I’m working with the “Hello, World Part 2” example at https://wxpython.org/pages/overview/#hello-world-part-2 . The wx.StaticText widget seems to be getting created correctly, but when the font is changed, the widget is not resized. It appears that the overview’s author intended for the widget to be resized when the font size is changed, and the screenshots back this up.
I’m not really even sure what the right way to resize it would be. I ended up calling st.SetSize(st.GetTextExtent(st.Label)), which seems like an odd way to do that.
I’m using the python3-wxgtk4.0 package on Ubuntu 19.04. A screenshot of the broken version (without the SetSize call) is attached, as well as source code for my fixed version with the “SetSize” call.
Am I doing something wrong? Is this just a behavior that changed in Phoenix, and the example is meant to be pre-Phoenix? This feels like I’m doing things the wrong way, but I’m new here and don’t know what the right way is.
A related doc note: in the wxPython wx.Window docs at https://wxpython.org/Phoenix/docs/html/wx.Window.html , the docs don’t describe GetTextExtent, but they do refer to it in the SetFont description. The GetFullTextExtent method description doesn’t describe how it differs from GetTextExtent. (I suspect the difference is that GetTextExtent only returns the x and y values from C++'s wxWindow::GetTextExtent, while Python’s GetFullTextExtent also returns the descent and externalLeading parameters. But this did take some digging to figure out.)
Thanks,
Piquan
xfr.py (938 Bytes)