Re: [wxPython-users] Help with wx.NoteBook Example listed in wxPy Wiki

299 views
Skip to first unread message

Tim Roberts

unread,
Nov 19, 2012, 12:47:17 PM11/19/12
to wxpytho...@googlegroups.com
Aditya wrote:
Hello World,

I am pretty new to Programming. I was going through the example of wx.NoteBook as listed over here at wxPy Wiki

However, when I run this code: 
  • a small Black Square 
  • appears on Top-Left 
  • of Page 1 of the App.
This Black Spot goes away once I navigate to other pages and come back to Page 1. I am using this example code to develop my first GUI Application and this 'out-of-order-Black-Spot' is irking me for last 3 days.

Have you modified the code at all?  I certainly don't see that square when I run that exact code on XP, nor do I see any conceivable reason why it would occur.

Are you running this from a command line, or from inside an IDE?  Which OS?
-- 
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Aditya

unread,
Nov 19, 2012, 1:08:19 PM11/19/12
to wxpytho...@googlegroups.com
I haven't modified the code at all. Using it 'as is' mentioned on that Wiki.

I am using Windows7, wxPython 2.9.4.0, Python 2.7.3. Have tried running it both from the Command Line as well as PyCharm IDE.

Regards.

grunculus

unread,
Nov 19, 2012, 1:25:22 PM11/19/12
to wxpytho...@googlegroups.com
Hi,

Please don't top-post your replies here.

On Mon, Nov 19, 2012 at 1:08 PM, Aditya <code....@gmail.com> wrote:

> On Monday, November 19, 2012 11:18:40 PM UTC+5:30, Tim Roberts wrote:
>>
>> Have you modified the code at all? I certainly don't see that square when
>> I run that exact code on XP, nor do I see any conceivable reason why it
>> would occur.
>>
>> Are you running this from a command line, or from inside an IDE? Which
>> OS?

> I haven't modified the code at all. Using it 'as is' mentioned on that Wiki.
>
> I am using Windows7, wxPython 2.9.4.0, Python 2.7.3. Have tried running it
> both from the Command Line as well as PyCharm IDE.
>
> Regards.

It works fine here for me as well. Win7 (US English).

Could it have something to do with your default code-page or
something? Try adding the following as the first line in the Python
script (starting in column 1):

# -*- coding: utf-8 -*-#

I don't know if it will help, but it does not hurt, here.

Good luck.

Cheers,
Scott.

Aditya

unread,
Nov 19, 2012, 1:37:07 PM11/19/12
to wxpytho...@googlegroups.com
Doesn't help. The problem still persists.

Regards. 

Robin Dunn

unread,
Nov 20, 2012, 1:50:15 PM11/20/12
to wxpytho...@googlegroups.com
On 11/19/12 3:17 AM, Aditya wrote:
> Hello World,
>
> I am pretty new to Programming. I was going through the example of
> wx.NoteBook as listed over here at wxPy Wiki
> <http://wiki.wxpython.org/Simple%20wx.Notebook%20Example>.
>
> However, when I run this code:
>
> * a small Black Square
> * appears on Top-Left
> * of Page 1 of the App.
>
> This Black Spot goes away once I navigate to other pages and come back
> to Page 1. I am using this example code to develop my first GUI
> Application and this 'out-of-order-Black-Spot' is irking me for last 3 days.
>
> Following is the snapshot of the App. I have used the code 'as is'
> listed on that Wiki page.

"The curse of the black spot..." ;-)

Things like that usually mean that there is some other window there,
perhaps one that is not parented properly, or that hasn't been added to
a sizer, etc. For example if one of the page panels was made a child of
the frame instead of the notebook, then it could manifest like that.

One way to figure it out would be to use the WIT. Once you've added it
to your program you can click on the Find button and then on the black
spot, and it should then be able to find that widget in the tree and
highlight it. If you can't tell from that where it is coming from then
you can assign names to the widgets (in their __init__ or by calling
SetName) and then the names will be displayed in the widget tree in the
WIT. http://wiki.wxpython.org/Widget_Inspection_Tool

--
Robin Dunn
Software Craftsman
http://wxPython.org

Aditya

unread,
Nov 21, 2012, 6:06:25 AM11/21/12
to wxpytho...@googlegroups.com
Hi Robin,

Thanks for your time. As you suggested, I have added WIT into the code. However, I still can't figure out the problem. Everything seems well parented to me and Sizers seem to be used appropriately. Following is the snapshot of what WIT shows when I use its Find feature.

I should also let you know, that if I remove Page1 from the code completely; ie; if I comment out Line 33 and Line 38 of the code listed on the wiki; then this Black Spot appears on Page 2. And disappears once I navigate to other pages.

Similarly, if I make any of the pages as Default; ie; if I make Page 3 as default by modifying Line 40 as:

nb.AddPage(page3, "Page 3", select=True)

Then, Black Spot appears in Page3 and disappears once I start navigating.

In Short, this Spot appears on the Page that is first displayed by the app and disappears once we navigate to other Pages.

Regards.

Robin Dunn

unread,
Nov 21, 2012, 12:25:50 PM11/21/12
to wxpytho...@googlegroups.com
> <http://wiki.wxpython.org/Widget_Inspection_Tool>
>

> Hi Robin,
>
> Thanks for your time. As you suggested, I have added WIT into the code.
> However, I still can't figure out the problem. Everything seems well
> parented to me and Sizers seem to be used appropriately. Following is
> the snapshot of what WIT shows when I use its Find feature.
>
> <http://i.imgur.com/CK1bQ.png>
>
> I should also let you know, that if I remove Page1 from the code
> completely; ie; if I comment out Line 33 and Line 38 of the code listed
> on the wiki; then this Black Spot appears on Page 2. And disappears once
> I navigate to other pages.
>
> Similarly, if I make any of the pages as Default; ie; if I make Page 3
> as default by modifying Line 40 as:
>
> nb.AddPage(page3, "Page 3", select=True)
>
>
> Then, Black Spot appears in Page3 and disappears once I start navigating.
>
> In Short, this Spot appears on the Page that is first displayed by the
> app and disappears once we navigate to other Pages.


Ok, the other possibility is that it is simply a refresh glitch where
Windows thinks that that square has already been drawn and so it's
excluded from the initial paint event. That can sometimes happen when
windows are first being created and shuffled around by the initial
layout. Try adding "wx.CallAfter(nb.Refresh)" to the end of
MainFrame.__init__. That will cause an extra paint event to be
delivered to the notebook and its visible children right after the
MainLoop starts.

Tim Roberts

unread,
Nov 21, 2012, 12:26:35 PM11/21/12
to wxpytho...@googlegroups.com
Aditya wrote:
>
> Thanks for your time. As you suggested, I have added WIT into the
> code. However, I still can't figure out the problem. Everything seems
> well parented to me and Sizers seem to be used appropriately.
> Following is the snapshot of what WIT shows when I use its Find feature.

However, your screen shot does show us something that you didn't mention
before: your desktop background color is black. Thus, rather than being
a black square drawn on top of everything else, what's likely happening
here is that the background color is showing through. You could test
that theory by changing the background color temporarily.

My best guess is that there is a cursor bug in your display driver.
It's restoring the wrong location after your window is drawn. By any
chance, is this running in a VM, or a Remote Desktop session, or a
TeamViewer session, or a GotoMyPC session, or one of the VNC clones? If
so, try this on real hardware and I'll bet you $100 it goes away.

Robin Dunn

unread,
Nov 21, 2012, 12:49:18 PM11/21/12
to wxpytho...@googlegroups.com
On 11/21/12 9:26 AM, Tim Roberts wrote:
> Aditya wrote:
>>
>> Thanks for your time. As you suggested, I have added WIT into the
>> code. However, I still can't figure out the problem. Everything seems
>> well parented to me and Sizers seem to be used appropriately.
>> Following is the snapshot of what WIT shows when I use its Find feature.
>
> However, your screen shot does show us something that you didn't mention
> before: your desktop background color is black. Thus, rather than being
> a black square drawn on top of everything else, what's likely happening
> here is that the background color is showing through. You could test
> that theory by changing the background color temporarily.

I saw it on one of my Windows PC too, it's not the background showing
through and has no discernible relationship with the cursor. It
initially starts out at the frame's client area (0,0) position and then
is shifted to the notebook's client area (0,0) after the initial layout.

My theory is that before everything is positioned and sized the panel,
the notebook and all the page windows are stacked on top of each other
at the frame's upper left corner and sized at about (20,20) with the
first page on top and all the page windows are shown (but not visible
because they are under the first page). When the notebook gets sized to
fill the panel it hides the other page windows and resizes/repositions
the first page window to be in the right place, but since it was on top
before Windows thinks that the (20,20) in the upper left corner has
already been painted and clips it out of the refresh region, but it
either never was painted or something (perhaps the themed drawing of the
notebook tabs) drew over that area before the page window was moved to
the correct position.

We used to see something similar in the demo when adding/removing
notebook pages when the current demo sample was changed. In that case
some Freeze/Thaw calls took care of it

Aditya

unread,
Nov 23, 2012, 6:41:47 AM11/23/12
to wxpytho...@googlegroups.com
First of all, extremely sorry for a late reply. My Internet Connection has been giving lots of problems for the last 2 days.

Now coming to the curse of the Black Spot. It's gone... The trick of refreshing the NoteBook by using wx.CallAfter(nb.Refresh) worked. Now, my 1st GUI App, which I am developing using that base code, looks pretty. Thanks for your help.

I would request you to update the code on that wiki providing the reasons thereof. Thank you once again.

Regards. 

Aditya

unread,
Nov 23, 2012, 6:46:03 AM11/23/12
to wxpytho...@googlegroups.com
No my Desktop background wasn't Black. I had edited the image so that the focus remains on the problem rather than the background. Neither am I running this in a VM or other VNC clones. Using the main Window 7 Desktop PC for this.

Do you still want to transfer $100 to my account. Let me know if you wish (or, has the offer expired in these last 2 days) :-)

Tim Roberts

unread,
Nov 24, 2012, 4:18:35 PM11/24/12
to wxpytho...@googlegroups.com
Aditya wrote:

On Wednesday, November 21, 2012 10:56:37 PM UTC+5:30, Tim Roberts wrote:

My best guess is that there is a cursor bug in your display driver.
It's restoring the wrong location after your window is drawn.  By any
chance, is this running in a VM, or a Remote Desktop session, or a
TeamViewer session, or a GotoMyPC session, or one of the VNC clones?  If
so, try this on real hardware and I'll bet you $100 it goes away.

No my Desktop background wasn't Black. I had edited the image so that the focus remains on the problem rather than the background. Neither am I running this in a VM or other VNC clones. Using the main Window 7 Desktop PC for this.

Do you still want to transfer $100 to my account. Let me know if you wish (or, has the offer expired in these last 2 days) :-)

I'm sorry, but I'm afraid you didn't satisfy the pre-conditions -- you were already running this on real hardware.

I do admit that my analysis was wrong...

Nathan McCorkle

unread,
Sep 15, 2014, 6:56:02 PM9/15/14
to wxpytho...@googlegroups.com


On Wednesday, November 21, 2012 9:25:57 AM UTC-8, Robin Dunn wrote: 
layout.  Try adding "wx.CallAfter(nb.Refresh)" to the end of
MainFrame.__init__.  That will cause an extra paint event to be
delivered to the notebook and its visible children right after the
MainLoop starts.

I was getting weird black spots and rectangles on start-up of a Notebook-based GUI, calling wx.CallAfter(self.nb.Refresh) fixed the problem, albeit with some discernible flicker. I also tried using the WIT's Find button then clicked on the black areas, but the WIT just showed the Panel I'd added to the Notebook (properly parented).  

Using wx-3.0.1-msw-classic on WinXP
Reply all
Reply to author
Forward
0 new messages