Here is an alternative idea that uses 2 sizers to automatically centre and resize the RichTextCtrl when the size of the frame changes, without having to explicitly program the sizes.
import wx
import wx.richtext as rt
DEBUG = True
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
if DEBUG:
width, height = 1000, 800
else:
width, height = wx.GetDisplaySize()
print(width, height)
self.SetSize((width, height))
self.SetBackgroundColour(wx.BLUE)
self.panel_1 = wx.Panel(self, wx.ID_ANY)
self.panel_1.SetBackgroundColour(wx.BLACK)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add((20, 20), 1, wx.EXPAND, 0)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_1.Add(sizer_2, 3, wx.ALL | wx.EXPAND, 0)
sizer_2.Add((20, 20), 1, wx.EXPAND, 0)
self.rtc = rt.RichTextCtrl(self.panel_1, wx.ID_ANY, style=wx.VSCROLL|wx.NO_BORDER)
sizer_2.Add(self.rtc, 2, wx.EXPAND, 0)
sizer_2.Add((20, 20), 1, wx.EXPAND, 0)
sizer_1.Add((20, 20), 1, wx.EXPAND, 0)
self.panel_1.SetSizer(sizer_1)
self.Layout()
for i in range(1, 90):
self.rtc.WriteText ("Hello RichTextControl!" + str(i))
self.rtc.Newline()
self.rtc.ScrollIntoView (self.rtc.GetLastPosition(), wx.WXK_END)
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, wx.ID_ANY, "")
self.SetTopWindow(self.frame)
if DEBUG:
self.frame.Show(show=True)
else:
self.frame.ShowFullScreen(show=True)
self.frame.Show()
return True
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
Lines such as:
sizer_1.Add((20, 20), 1, wx.EXPAND, 0)
add a spacer to the sizer with an arbitrary initial size of (20, 20) which is then overridden by the proportion values and the wx.EXPAND flag.
By varying the proportion values of the spacers and of the RichTextCtrl you can determine the ratio of the dimensions of the RichTextCtrl compared to the Panel.