Creating a panel in the __init__ method of the frame is fine.
It's difficult to understand from the posted code what kind of layout
you actually want to accomplish, but certainly your structure of init
code, sizers and widgets is overly complicated.
Also, I'm not sure whether EVT_KEY_DOWN for a read only text ctrl will
have any effect.
Then, using EXPAND with a single-line text ctrl in a horizontal sizer is
probably not what you want. It will make grow the text ctrl vertically,
but the number of lines is still 1. Using ALIGN_LEFT in a horizontal
sizer does not have an effect. Maybe it would even trigger an assertion
with more recent versions of wxPython.
Anyway, I have just re-built something similar and this is some
straightforward init code.
(Just ignore the code before self.panel for now or keep your own code
for this.)
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, style=wx.DEFAULT_FRAME_STYLE)
self.SetSize((850, 850))
self.SetTitle("Accessible Calculator")
self.SetName("Accessible Calculator.")
self.panel = wx.Panel(self, wx.ID_ANY, style=wx.WANTS_CHARS)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox.Add(hbox, 1, wx.EXPAND, 0)
self.sum = wx.TextCtrl(self.panel, wx.ID_ANY, "",
style=wx.TE_READONLY)
self.sum.SetFont(wx.Font(12, wx.FONTFAMILY_MODERN,
wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, ""))
hbox.Add(self.sum, 0, wx.ALL | wx.EXPAND, 5)
self.history = wx.TextCtrl(self.panel, wx.ID_ANY, "",
style=wx.TE_READONLY)
hbox.Add(self.history, 0, wx.EXPAND, 3)
self.panel.SetSizer(vbox)
self.Layout()
self.Centre()
self.Bind(wx.EVT_KEY_DOWN, self.press, self.panel)
self.Bind(wx.EVT_KEY_DOWN, self.press, self.sum)
Regards,
Dietmar