menubar and notebook/panel not appearing together in windows OS

I’ve been having layout issues cross-platform, but I think I’ve narrowed it down. It’s such a very basic looking problem, but it has been rather irritating. I’m using python 2.7.6. and it runs fine on ubuntu (wx version 2.8.12), but running it on windows xp (wx version 3.0), causes it to have layout issues, where it looks like the notebook (or just the panel itself, i’ve tried both cases) was never added to a sizer, and you can see the little block in the top left under then menu. Removing the menu by just commenting out the stuff between the comment lines will let the notebook/panel appear, but obviously there won’t be a menu bar. Anyone know the (probably obvious) answer to have both the menubar and panel/notebook appear normally in windows?

Oh, also, if anyone knows why wx.ID_EXIT doesn’t work in windows. In the line, file_item = file_menu.Append(ID_EXIT,‘Quit\tCTRL+Q’), used to be wx.ID_EXIT instead of ID_EXIT, but it didn’t work cross-platform, since the ctrl+q shortcut disappears, so I just wrote it out explicitly which worked for both systems. Definitely not important since it’s fixed, but I would like to have the shorthand back.

···

import wx

ID_EXIT = wx.NewId()

class MainFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, wx.ID_ANY,“Foo”,size=(600,400))
panel = wx.Panel(self)

    ##########################################
    menu_bar = wx.MenuBar()
    file_menu = wx.Menu()
    file_item = file_menu.Append(ID_EXIT,'Quit\tCTRL+Q')
    menu_bar.Append(file_menu,'File')
    self.SetMenuBar(menu_bar)
    self.Bind(wx.EVT_MENU,self.OnQuit,file_item)
    ##########################################
    notebook = Notebook(panel)
    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(notebook, 1, wx.ALL | wx.EXPAND, 5)
    panel.SetSizer(sizer)

    self.Center()
   
def OnQuit(self,event):
    self.Close()

class TabPanelOne(wx.Panel):
def init(self, parent):
wx.Panel.init(self, parent=parent, id=wx.ID_ANY)

class Notebook(wx.Notebook):
def init(self, parent):
wx.Notebook.init(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)

    tab1 = TabPanelOne(self)
    tab1.SetBackgroundColour("Gray")
    self.AddPage(tab1, "Bar")

if name == “main”:
app = wx.App(False)
frame = MainFrame()
frame.Show()
app.MainLoop()

Ahh, the "little block".. a classic of wxPython meets Windows. Watch
this: try dragging the corner of the frame to make the frame larger.
(which forces a Layout().

OK, so add this line under self.Center():

panel.Layout()

And yes, this is not necessary on Linux. Robin provided some detail about
this, which I reproduce below:

"For the record, this is usually because if you construct the windows with
a fixed size and/or show them before the sizer has been set, then there
could be cases that they do not get a size event after the sizer has been
set. With no size events the sizer needs some help to do that initial
layout."

Che

···

On Fri, Feb 28, 2014 at 8:13 PM, <mshigemo@gmail.com> wrote:

I've been having layout issues cross-platform, but I think I've narrowed
it down. It's such a very basic looking problem, but it has been rather
irritating. I'm using python 2.7.6. and it runs fine on ubuntu (wx version
2.8.12), but running it on windows xp (wx version 3.0), causes it to have
layout issues, where it looks like the notebook (or just the panel itself,
i've tried both cases) was never added to a sizer, and you can see the
little block in the top left under then menu.

Awesome, works like a charm, and actually solved two other issues I was having, one of which was white squares (which disappeared after mouseover) covering my checklist’s boxes, and the other was the default value not being shown in a combobox/drop down list. Thanks again.

Mike

···

On Friday, February 28, 2014 8:28:43 PM UTC-8, Che M wrote:

On Fri, Feb 28, 2014 at 8:13 PM, mshi...@gmail.com wrote:

I’ve been having layout issues cross-platform, but I think I’ve narrowed it down. It’s such a very basic looking problem, but it has been rather irritating. I’m using python 2.7.6. and it runs fine on ubuntu (wx version 2.8.12), but running it on windows xp (wx version 3.0), causes it to have layout issues, where it looks like the notebook (or just the panel itself, i’ve tried both cases) was never added to a sizer, and you can see the little block in the top left under then menu.

Ahh, the “little block”… a classic of wxPython meets Windows. Watch this: try dragging the corner of the frame to make the frame larger. (which forces a Layout().

OK, so add this line under self.Center():

panel.Layout()

And yes, this is not necessary on Linux. Robin provided some detail about this, which I reproduce below:

“For the record, this is usually because if you construct the windows with a fixed size and/or show them before the sizer has been set, then there could be cases that they do not get a size event after the sizer has been set. With no size events the sizer needs some help to do that initial layout.”

Che