[Tutor] Fwd: Pi xels
John Steedman
johnsteedman360 at gmail.com
Thu May 9 21:38:05 CEST 2013
I once dabbled with wxPython. The code below may not run straight off as
I've cut it out of a bigger routine, but it may give you a flavour of a
basic (very basic) set up.
import wx
import math
def drawCircle (radius, canvas, strCol):
centre = (100,100)
cX = centre[0]
cY = centre[1]
dc = canvas
dc.SetPen(wx.Pen(strCol, 5))
x1 = 0
y1 = math.sqrt ( math.pow (radius,2) - math.pow(x1, 2) )
for x2 in range ( 1, radius + 1 , 1 ):
y2 = math.sqrt ( math.pow (radius,2) - math.pow(x2, 2) )
dc.DrawLine ( cX+ x1 , yCorr ( cY + y1 ), cX + x2, yCorr (cY + y2) )
dc.DrawLine ( cX+ x1 , yCorr ( cY - y1 ), cX + x2, yCorr (cY - y2) )
dc.DrawLine ( cX- x1 , yCorr ( cY + y1 ), cX - x2, yCorr (cY + y2) )
dc.DrawLine ( cX- x1 , yCorr ( cY - y1 ), cX - x2, yCorr (cY - y2) )
y1 = y2
x1 = x2
def on_paint(event):
dc = wx.PaintDC(event.GetEventObject())
dc.Clear()
drawCircle ( 50, dc, 'GREEN')
app = wx.App(False)
frame = wx.Frame(None, title="Draw on Panel")
panel = wx.Panel(frame)
panel.Bind(wx.EVT_PAINT, on_paint)
#panel.Bind(wx.EVT_LEFT_DOWN, on_mouseClick)
panel.SetFocusIgnoringChildren()
panel.Bind(wx.EVT_KEY_DOWN, on_KeyDown )
frame.Show(True)
app.MainLoop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130509/bc471403/attachment.html>
More information about the Tutor
mailing list