WxPython 4.0.1,Python 2.7.15rc1,Ubunutu 18.04.1
我在对话框中有一个wx.StaticText消息。如果我使用原始字体规格在wx.StaticText对象上调用SetFont,则其布局会发生变化,最后会被截断。如果未调用SetFont,则布局正确。下面是创建2个对话框的最少代码,第一个不调用正确显示的SetFont,第二个调用不想要的结果的SetFont。
我的最初目标是将文本更改为等宽字体wx.FONTFAMILY_TELETYPE,这导致发现此问题。我找不到.Fit和.Layout调用的任何组合来使其正常工作。
#!/usr/bin/python
import wx
import wx.lib.stattext
class UserDialog(wx.Dialog):
def __init__(self, setfont, msg, title):
wx.Dialog.__init__(self, None, wx.ID_ANY, title)
self.sizer = wx.BoxSizer(wx.VERTICAL)
st= wx.StaticText(self, wx.ID_ANY, msg)
if setfont:
f=st.GetFont()
st.SetFont(wx.Font(f.GetPointSize(), f.GetFamily(), f.GetStyle(), f.GetWeight()))
self.sizer.Add( st, 0, wx.ALL, 5 )
self.SetSizer(self.sizer)
self.sizer.Fit(self)
#self.sizer.Layout()
self.Layout()
self.Show(True)
print self.GetSize()
print self.sizer.GetSize()
if __name__ == '__main__':
print 'wx.VERSION=', wx.VERSION
wxapp = wx.App()
d1_good= UserDialog(False, 'Well hello there, this is a long message!', 'A Dialog Title')
d2_bad = UserDialog(True, 'Well hello there, this is a long message!', 'A Dialog Title')
wxapp.MainLoop()