本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。允许非商业转载,但应注明作者及出处。
作者:liuyuan_jq
2011-04-10
#!/usr/bin/env python # -*- coding:utf-8 -*- import wx import wx.lib.ogl as ogl class MyFrame(wx.Frame): def __init__(self): wx.Frame.__init__( self, None, wx.ID_ANY, title="explore wx.lib.ogl", size=(400,300)) # 创建画布 canvas = ogl.ShapeCanvas(self) canvas.SetBackgroundColour("yellow") # 创建图像 diagram = ogl.Diagram() # marry the two ... canvas.SetDiagram(diagram) diagram.SetCanvas(canvas) # 创建圆 # create some standard shapes ... # (check how creation order affects overlap) circle = ogl.CircleShape(100.0) # radius circle.SetX(75.0) # center x circle.SetY(75.0) circle.SetPen(wx.RED_PEN) circle.SetBrush(wx.CYAN_BRUSH) # 将圆添加到画布 canvas.AddShape(circle) # 创建文本 text = ogl.TextShape(250, 30) # (w, h) text.SetX(180) # center x text.SetY(240) text.AddText("you can drag the circle or the text") # 将文本添加到画布 canvas.AddShape(text) # 显示画布上的内容 diagram.ShowAll(True) # 创建sizer # use v box sizer sizer = wx.BoxSizer(wx.VERTICAL) # 将画布添加到sizer # canvas will grow as frame is stretched sizer.Add(canvas, 1, wx.GROW) # 设置sizer self.SetSizer(sizer) app = wx.App() ogl.OGLInitialize() MyFrame().Show() app.MainLoop()