Help in wxpython

Krishnakant hackingkk at gmail.com
Wed Dec 2 23:05:56 EST 2009


On Wed, 2009-12-02 at 00:20 -0800, madhura vadvalkar wrote:
> Hi
> 
> I am trying to write an  PAINT like application where on the mouse
> click a circle is drawn on canvas. I am new to python and using
> wxpython to create this.
> 
> here is the code:
> 
> import wx
> 
> class SketchWindow(wx.Window):
> 
>     def __init__ (self, parent,ID):
> 
>         wx.Window.__init__(self, parent, ID)
> 
>         self.panel =wx.Panel(self, size= (350,350))
>         self.pen=wx.Pen( 'blue',4)
>         self.pos=(0,0)
>         self.InitBuffer()
>         self.Bind(wx.EVT_LEFT_DOWN,self.OnLeftDown)
> 
>     def InitBuffer(self):
> 
>         size=self.GetClientSize()
>         self.Buffer=wx.EmptyBitmap(size.width,size.height)
>         dc=wx.BufferedDC(None,self.buffer)
>         dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
>         dc.Clear()
>         self.Drawcircle(dc)
>         self.reInitBuffer=False
> 
>     def OnLeftDown(self,event):
>         self.pos=event.GetPositionTuple()
>         self.CaptureMouse()
> 
>     def Drawcircle(self,dc):
>         pen=wx.Pen(colour,thickness,wx.SOLID)
>         dc.SetPen(pen)
>         dc.DrawCircle(self.pos.x,self.pos.y,r)
> 
> class SketchFrame(wx.Frame):
>     def __init__(self, parent):
> 
>         wx.Frame.__init__(self, parent, -1, "Sketch Frame",size=(800,600))
>         self.sketch = SketchWindow(self, -1)
> 
> if __name__=='__main__':
>     app=wx.PySimpleApp()
>     frame=SketchFrame(None)
>     frame.Show(True)
>     app.MainLoop()
> 
> I am getting the following error:
> 
> Traceback (most recent call last):
>   File "C:/Python26/circle.py", line 42, in <module>
>     frame=SketchFrame(None)
>   File "C:/Python26/circle.py", line 38, in __init__
>     self.sketch = SketchWindow(self, -1)
>   File "C:/Python26/circle.py", line 12, in __init__
>     self.InitBuffer()
>   File "C:/Python26/circle.py", line 19, in InitBuffer
>     dc=wx.BufferedDC(None,self.buffer)
> AttributeError: 'SketchWindow' object has no attribute 'buffer'
> 
> Please tell me what I am doing wrong.
> 
> Thanks
Madhura, Sorry to be a bit off-topic, but, I would really recommend you
to use pygtk instead of wx.
For one thing, the developers at pygtk are very active (they have their
mailing list as well ) and it comes by default with python on almost all
linux distros.  You can also easily install it on windows.

Most important, the api for pygtk is closely similar to wx.
Not to mention the quick responses you will get with pygtk related
problems.

Happy hacking.
Krishnakant.




More information about the Python-list mailing list