I tried it on someone else’s computer, The same problem exists also. Why and how to fix?
wxpython version:4.0.6
platform:windows 10.0
import wx
class PageOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.title= wx.StaticText(self, wx.ID_ANY, '招采制度索引V1.0')
#Label
self.labelOne = wx.StaticText(self, wx.ID_ANY, "住宅集团采购条线考核办法")
# CheckListBox
ckList1 = ['住宅集团采购条线考核管理办法', '附:2019年考核体系汇总']
self.cb1 = wx.CheckListBox(self, wx.ID_ANY, size=(20, 45), choices=ckList1, style=0)
self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckBox, self.cb1)
self.logger = wx.TextCtrl(self, size=(30,30), style=wx.TE_MULTILINE | wx.TE_READONLY)
# buttons
self.button =wx.Button(self, label="打开文件")
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.moreBtn = wx.Button(self, label="查看更多")
self.Bind(wx.EVT_BUTTON, self.moClick, self.moreBtn)
self.clBtn = wx.Button(self, wx.ID_ANY, '清空')
self.Bind(wx.EVT_BUTTON, self.OnCl, self.clBtn)
# create some sizers
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
cbSizer1 = wx.BoxSizer(wx.HORIZONTAL)
moSizer = wx.BoxSizer(wx.HORIZONTAL)
loggerSizer = wx.BoxSizer(wx.HORIZONTAL)
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
labelOneSizer = wx.BoxSizer(wx.HORIZONTAL)
titleSizer.Add(self.title, 0, wx.ALL)
labelOneSizer.Add(self.labelOne, 0, wx.ALL)
cbSizer1.Add(self.cb1, 1, wx.ALL)
moSizer.Add(self.moreBtn, 0, wx.ALL)
loggerSizer.Add(self.logger, 1, wx.ALL|wx.EXPAND)
buttonSizer.Add(self.button, 0, wx.ALL)
buttonSizer.Add(self.moreBtn, 0, wx.ALL)
buttonSizer.Add(self.clBtn, 0, wx.ALL)
topSizer.Add(titleSizer, 0, wx.CENTER, 3)
topSizer.Add(wx.StaticLine(self,), 0, wx.ALL|wx.EXPAND, 3)
topSizer.Add(labelOneSizer, 0,wx.ALL|wx.EXPAND, 3)
topSizer.Add(cbSizer1, 0, wx.ALL|wx.EXPAND, 3)
topSizer.Add(loggerSizer, 0, wx.ALL|wx.EXPAND, 3)
topSizer.Add(buttonSizer, 0, wx.CENTER)
topSizer.Add(wx.StaticLine(self,), 0, wx.ALL|wx.EXPAND, 3)
self.SetSizerAndFit(topSizer) #Layout sizers
def EvtCheckBox(self, event):
pass
def moClick(self, event):
pass
def OnClick(self,event):
pass
def OnCl(self, e):
pass
class PageTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
app = wx.App(False)
frame = wx.Frame(None, title="制度地图", pos=(480,100), size=(400,600),
style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
nb = wx.Notebook(frame)
nb.AddPage(PageOne(nb), "招采制度地图")
nb.AddPage(PageTwo(nb), "其他相关制度")
frame.Show()
app.MainLoop()
This a little example, it has the same problem. you can run it and take a closer look.
import wx
class PageOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.title= wx.StaticText(self, wx.ID_ANY, 'this is a example')
#Label
self.labelOne = wx.StaticText(self, wx.ID_ANY, "this is a example")
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
labelOneSizer = wx.BoxSizer(wx.HORIZONTAL)
titleSizer.Add(self.title, 0, wx.ALL)
labelOneSizer.Add(self.labelOne, 0, wx.ALL)
topSizer.Add(titleSizer, 0, wx.CENTER, 3)
topSizer.Add(wx.StaticLine(self,), 0, wx.ALL|wx.EXPAND, 3)
topSizer.Add(labelOneSizer, 0,wx.ALL|wx.EXPAND, 3)
self.SetSizerAndFit(topSizer) #Layout sizers
class PageTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
app = wx.App(False)
frame = wx.Frame(None, title="this is a example", pos=(480,100), size=(400,600),
style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
nb = wx.Notebook(frame)
nb.AddPage(PageOne(nb), "this is a example")
nb.AddPage(PageTwo(nb), "this is a example")
frame.Show()
app.MainLoop()
A more littler example, you can compare it with the above, the black stripe becomes longer while the more widgets setted.
import wx
class PageOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.title= wx.StaticText(self, wx.ID_ANY, 'this is a example')
#Label
self.labelOne = wx.StaticText(self, wx.ID_ANY, "this is a example")
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
labelOneSizer = wx.BoxSizer(wx.HORIZONTAL)
titleSizer.Add(self.title, 0, wx.ALL)
labelOneSizer.Add(self.labelOne, 0, wx.ALL)
topSizer.Add(titleSizer, 0, wx.CENTER, 3)
topSizer.Add(wx.StaticLine(self,), 0, wx.ALL|wx.EXPAND, 3)
topSizer.Add(labelOneSizer, 0,wx.ALL|wx.EXPAND, 3)
self.SetSizerAndFit(topSizer) #Layout sizers
app = wx.App(False)
frame = wx.Frame(None, title="this is a example", pos=(480,100), size=(400,600),
style=wx.DEFAULT_FRAME_STYLE^wx.RESIZE_BORDER^wx.MAXIMIZE_BOX)
panel = PageOne(frame)
frame.Show()
app.MainLoop()
Here is the problem: wx.Notebook, I delete the ‘wx.Notebook’, the black stripe disappear, the app become normal. But i have no idea to fix the bug. Someone can help me?
Since you have turned off the frame styles for resizing the frame, and since the frame is given a size before the other widgets are created, then it’s possible that there isn’t an initial size event where the auto-layout of the notebook and its children can happen. On Windows, when a notebook is involved in this kind of situation then it can sometimes not do the initial paint of some of area around the tabs because it thinks the page windows are there.
There are a couple possible workarounds you can try.
You can try not setting the frame’s size until after you have set up everything else within the frame, by removing the size from wx.Frame(...)
and then calling SetSize
just before showing it.
If that doesn’t help then giving the frame an extra size event with SendSizeEvent
or a Refresh
after the main loop has started can usually help. wx.CallAfter
can be used to invoke a method later, when the main loop has been started.
Thank you very much, the SetSize worked.