views:

161

answers:

2

Why does my code print the lines gray instead of black?

import wx

class MyFrame(wx.Frame):
    def __init__(self,*args,**kwargs):
        wx.Frame.__init__(self,*args,**kwargs)
        self.panel=wx.Panel(self,-1,size=(1000,1000))
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)

        self.bitmap=wx.EmptyBitmapRGBA(1000,1000,255,255,255,255)

        dc=wx.MemoryDC()
        dc.SelectObject(self.bitmap)
        dc.SetPen(wx.Pen(wx.NamedColor("black"),10,wx.SOLID))
        dc.DrawCircle(0,0,30)
        dc.DrawLine(40,40,70,70)
        dc.Destroy()

        self.Show()

    def on_size(self,e=None):
        self.Refresh()

    def on_paint(self,e=None):
        dc=wx.PaintDC(self.panel)
        dc.DrawBitmap(self.bitmap,0,0)
        dc.Destroy()

if __name__=="__main__":
    app=wx.PySimpleApp()
    my_frame=MyFrame(parent=None,id=-1)
    app.MainLoop()
A: 

Ok I tested with newer version of wx(2.8.9.2)

and Now I wonder why it is even working on your side. you are trying to paint Panel but overriding the paint event of Frame

instead do this

self.panel.Bind(wx.EVT_PAINT, self.on_paint)

and all will be fine

Anurag Uniyal
Sounded sensible, but I tried it and the lines still come out gray.I changed `self.Bind(wx.EVT_PAINT, self.on_paint)` to `self.panel.Bind(wx.EVT_PAINT, self.on_paint)`. I am using 2.8.9.2 as well, on Python 2.6 on Windows XP
cool-RR
right still gray ...
RSabet
+1  A: 

Beside the frame/panel paint problem already pointed out the color problem is due to the alpha channel of the 32 bit bitmap.

I remember having read to use wx.GCDC instead of wx.DC.

RSabet