Problems with GetPixel and Ubuntu

I tried this code under kubuntu and ubuntu 10.04 (python 2.6,
wxPython 2.8), but I found meaningless RGB values (B always 0, for
example, independently from the background color). An other strange
thing that I found is that, if I substitute ClientDC with ScreenDC, it
works (obviously after a coordinate correction).

import wx
class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(500, 350))
        self.SetBackgroundColour(wx.BLUE)
        self.dc=wx.ClientDC(self)
        # Binding Events
        self.Bind(wx.EVT_MOTION, self.ilmousesimuove)
        self.Centre()
        self.Show(True)

        # Setting methods
    def ilmousesimuove(self,event):
        x,y=event.GetPosition()
        colore = self.dc.GetPixel(x,y)
        print x,y," colore: ", colore

app = wx.App()
MainWindow(None, -1, "titolo")
app.MainLoop()

Yes, what you're doing is not valid. A DC is a transient structure --
it comes and goes. You can't fetch one at initialization time and
then hold on to it forever (unless you change the window attributes).
Instead, you should do
    dc = wx.ClientDC(self)
in the event handler.

···

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

On Sep 15, 9:29 am, andreaconsole <andreacons...@gmail.com> wrote:

I tried this code under kubuntu and ubuntu 10.04 (python 2.6,
wxPython 2.8), but I found meaningless RGB values (B always 0, for
example, independently from the background color). An other strange
thing that I found is that, if I substitute ClientDC with ScreenDC, it
works (obviously after a coordinate correction).

Thanks Tim, you got it!

···

On Sep 16, 6:28 pm, Tim Roberts <t...@probo.com> wrote:

Yes, what you're doing is not valid. A DC is a transient structure --
it comes and goes. You can't fetch one at initialization time and
then hold on to it forever (unless you change the window attributes).
Instead, you should do
dc = wx.ClientDC(self)
in the event handler.
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

On Sep 15, 9:29 am, andreaconsole <andreacons...@gmail.com> wrote:

> I tried this code under kubuntu and ubuntu 10.04 (python 2.6,
> wxPython 2.8), but I found meaningless RGB values (B always 0, for
> example, independently from the background color). An other strange
> thing that I found is that, if I substitute ClientDC with ScreenDC, it
> works (obviously after a coordinate correction).