Why does my code print the lines gray instead of black?
Thanks,
Ram
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()
cool-RR wrote:
Why does my code print the lines gray instead of black?
They are black for me.
I'm using OS-X 10.4, python2.5, wxPython'2.8.9.1'
What system are you on?
-Chris
···
Thanks,
Ram
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()
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
I'm using OS-X 10.4, python2.5, wxPython'2.8.9.1'
What system are you on?
win xp, python 2.6, wxpython 2.8.9.2
Robin
May 12, 2009, 3:15am
4
cool-RR wrote:
Why does my code print the lines gray instead of black?
Because drawing on a 32-bit context with alpha has undefined results when using a non alpha-aware DC. You have other problems in your code as well: you're using the frame's paint event to draw the panel, and you've overridden the frame's EVT_SIZE so it's not going to autosize the panel to fill the frame. (Although you can get the same effect of calling Refresh in EVT_SIZE simply by using a non-default style, so it isn't really needed.)
import wx
class MyFrame(wx.Frame):
def __init__(self,*args,**kwargs):
wx.Frame.__init__(self,*args,**kwargs)
self.panel=wx.Panel(self, style=wx.FULL_REPAINT_ON_RESIZE)
self.panel.Bind(wx.EVT_PAINT, self.on_paint)
self.panel.Bind(wx.EVT_ERASE_BACKGROUND, lambda e: None)
self.bitmap=wx.EmptyBitmapRGBA(1000,1000,255,255,255,255)
dc=wx.GCDC(wx.MemoryDC(self.bitmap))
dc.SetPen(wx.Pen(wx.NamedColor("black"),10,wx.SOLID))
dc.DrawCircle(0,0,30)
dc.DrawLine(40,40,70,70)
del dc
self.Show()
def on_paint(self,e=None):
dc=wx.PaintDC(self.panel)
dc.DrawBitmap(self.bitmap,0,0)
if __name__=="__main__":
app=wx.PySimpleApp()
my_frame=MyFrame(parent=None,id=-1)
app.MainLoop()
···
--
Robin Dunn
Software Craftsman