WxPython not rendering correctly

Question:

I create a WxPython notebook after a call from a menu item, but unfortunately it’s not rendering correctly (only a little blue shape in the corner is visible). I have to manually resize the window and it pops back to working order like the second picture.

wrong

correct

Code:

def load_notebook(self):
    panel = wx.Panel(self)
    sizer = wx.BoxSizer(wx.VERTICAL)
    notebook = apps.srp.main.Notebook(panel)
    sizer.Add(notebook, 1, wx.ALL | wx.EXPAND, 5)
    panel.SetSizer(sizer)

Things I’ve tried :

self.Layout()
self.Refresh()
self.Update()
notebook.Layout()
notebook.Refresh()
notebook.Update()

both in the main directory and the folder where the notebook and panels are located.

Using

  • wxPython-Phoenix (3.0.3.dev1820+49a8884)
  • Python 3.4
  • OSX 10.10
Asked By: MaxQ

||

Answers:

So after some more tweaking and the tip of using the Widget Inspection Tool, it was indeed the fact that the panel that held the notebook was not being sized according to the frame (assuming the default size I guess of 20×20 pixels which is the little blue spot that I saw)

The solution was to add the following after adding the notebook:

    sizer_parent = wx.BoxSizer()
    sizer_parent.Add(panel, 1, wx.ALL | wx.EXPAND, 5)
    self.SetSizer(sizer_parent)
    self.Layout()
Answered By: MaxQ

I had the same exact issue where a combo box would only go into it’s position if the window was resized but the solution posted didn’t work for me. I got around it by creating a function that simply just resizes the window for you:

def forceRefresh(self):
    self.SetSize((self.GetSize().width, self.GetSize().height+1))
    self.SetSize((self.GetSize().width, self.GetSize().height-1))

While not optimal it got the trick done for me so hopefully it can help someone else out there.

Answered By: Adam Lang

Although this question is old, I am having a similar problem: a page layout in a notebook was a shambles until I resized the frame, using the mouse. Then just fine. Eventually, I realised that the simple answer is to force it during startup. In the OnInit callback, where I had all my startup code, added:

w,h = mainframe.GetSize()
mainframe.SetSize((w+1,h-1))
mainframe.SetSize((w,h))

just before returning True. Everything now works fine. Weird or what.

Answered By: hamiljf
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.