1

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
3
  • I am missing the part where you actually place the panel somewhere. I suppose your window a sizer, then you must add the panel into the sizer. Commented Apr 27, 2015 at 6:40
  • 1
    My guess would be that the parent of the panel you create in load_notebook is not giving space to the notebook. Or you need to add that panel to the sizer of the parent. In other words we need to see more of your code. A good tool to debug sizer issues like this is the WIT - wiki.wxpython.org/Widget%20Inspection%20Tool Commented Apr 27, 2015 at 6:41
  • @Werner Thanks for that tip. The frame renders correctly but (indeed) the panel child of it that holds the actual notebook is is screwed up- it has a size of 20x20 pixels which is the little blue shape I am seeing. Commented Apr 27, 2015 at 9:04

3 Answers 3

2

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 20x20 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() 
Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Often things like this happen because the initial size of the parent window has already been set, so there are no more size events until the user resizes the window. With no size events, there are no auto-layouts triggered. wx provides the SendSizeEvent method to send an artificial size event so the auto-layout can be redone at that point in time.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.