import wx from wx import glcanvas from OpenGL.GL import * from OpenGL.GLUT import * class MyCanvas(glcanvas.GLCanvas): def __init__(self,parent): glcanvas.GLCanvas.__init__(self,parent,-1) glClearColor(0.0,0.0,0.0,0.0) self.Bind(wx.EVT_PAINT,self.OnPaint) self.Bind(wx.EVT_SIZE,self.OnSize) def OnPaint(self,event): dc=wx.PaintDC(self) self.SetCurrent() glClear(GL_COLOR_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() glColor3f(0.0,1.0,0.0) glLineWidth(1.0) glOrtho(0.0,5.0,0.0,5.0,-1.0,1.0) self.drawMyThings() self.SwapBuffers() def drawMyThings(self): point=[(1.0,1.0),(1.0,2.0),(2.0,2.0),(2.0,1.0)] point2=[[1.0,1.0],[1.0,2.0],[2.0,2.0],[2.0,1.0]] glBegin(GL_LINE_LOOP) glVertex2fv(point2[0]) glVertex2fv(point2[1]) glVertex2fv(point2[2]) glVertex2fv(point2[3]) glEnd() def OnSize(self,event): pass if __name__=="__main__": app=wx.PySimpleApp() frame=wx.Frame(None) frame.SetSize((400,400)) canvas=MyCanvas(frame) frame.Show() app.MainLoop() 使用元组或者列表都可以做为glVertex*v(v)的参数,测试程序都可以运行。