Oddness with wxNotebook

75 views
Skip to first unread message

floati...@gmail.com

unread,
Dec 18, 2017, 11:55:31 AM12/18/17
to wxPython-users

I have this very basic code:

import wx


class MyMultiDlg(wx.Dialog):
   
def __init__(self, parent):
        wx
.Dialog.__init__(self, parent, -1, '', style=wx.DEFAULT_DIALOG_STYLE, size=(650,350))

       
       
        p
= wx.Panel(self)
       
self.nb = wx.Notebook(p)

       
self.nb.AddPage(test(self.nb), "one")
       
self.nb.AddPage(test2(self.nb), "two")
       

        sizer
= wx.BoxSizer()
        sizer
.Add(self.nb, 1, wx.EXPAND)
        p
.SetSizer(sizer)

       
class test(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)
       
       
class test2(wx.Panel):
   
def __init__(self, parent):
        wx
.Panel.__init__(self, parent)

       
#----------------------------------------------------------------------
class MyApp(wx.App):
   
def OnInit(self):
        dlg
= MyMultiDlg(None)
        dlg
.ShowModal()
        dlg
.Destroy()
       
return True
if __name__ == "__main__":
    myapp
= MyApp(redirect=False)
    myapp
.MainLoop()

It generates a two page notebook but page one has a small black square top left, this is even visible in the official demo. Any ideas what is going on?
The square vanishes when changing pages and doesn't return until next run.
(Python3.6, wxpython 4.0.0b2, windows10)
Thanks.



Tim Roberts

unread,
Dec 18, 2017, 2:24:34 PM12/18/17
to wxpytho...@googlegroups.com
floati...@gmail.com wrote:
>
> I have this very basic code:
> ...
> It generates a two page notebook but page one has a small black square
> top left, this is even visible in the official demo. Any ideas what is
> going on?
> The square vanishes when changing pages and doesn't return until next run.
> (Python3.6, wxpython 4.0.0b2, windows10)

Yes, this is some kind of a bug in the notebook code that has been
around for a long time.  It's not a real window, and it's not the
background showing through.  Here's a thread from 2012 that talks about
the same issue, and my harebrained theory on what causes it:
    https://groups.google.com/forum/#!topic/wxpython-users/bdh7xxYMxho

The workaround is to force a refresh by adding this to your dialog's
__init__:
    wx.CallAfter( self.nb.Refresh )

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

floati...@gmail.com

unread,
Dec 19, 2017, 2:19:06 AM12/19/17
to wxPython-users
Thanks Tim, the workaround tidied it up nicely.
Reply all
Reply to author
Forward
0 new messages