Python/wxPython/Graphics: Difference between revisions
Jump to navigation
Jump to search
| Line 50: | Line 50: | ||
* [https://cairographics.org/documentation/pycairo/2/reference/context.html#class-context Context class of PyCairo] | * [https://cairographics.org/documentation/pycairo/2/reference/context.html#class-context Context class of PyCairo] | ||
* [https://cairocffi.readthedocs.io/en/stable/api.html#context Context class of CairoCFFI] | * [https://cairocffi.readthedocs.io/en/stable/api.html#context Context class of CairoCFFI] | ||
<source lang="python" line="true" highlight="14- | <source lang="python" line="true" highlight="14-23"> | ||
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||
import wx | import wx | ||
| Line 65: | Line 65: | ||
def OnPaint(self, evt): | def OnPaint(self, evt): | ||
dc = wx.PaintDC(self.mainFrame) | # dc = wx.BufferedPaintDC(self.mainFrame) | ||
# dc = wx.PaintDC(self.mainFrame) | |||
# dc = wx.ClientDC(self.mainFrame) | |||
dc = wx.WindowDC(self.mainFrame) | |||
ctx = wx.lib.wxcairo.ContextFromDC(dc) | ctx = wx.lib.wxcairo.ContextFromDC(dc) | ||
ctx.set_line_width(5) | ctx.set_line_width(5) | ||
Revision as of 02:16, 22 March 2019
wx.DC hierarchy
Draw line by PaintDC
#!/usr/bin/env python3
import wx
class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(None, -1, 'Hello World!')
frame.Bind(wx.EVT_PAINT, self.OnPaint)
frame.Show()
self.mainFrame = frame
return True
def OnPaint(self, evt):
dc = wx.PaintDC(self.mainFrame)
dc.DrawLine(10, 10, 200, 10)
if __name__ == '__main__':
app = MyApp()
app.MainLoop()
Draw line by Cairo
#!/usr/bin/env python3
import wx
import wx.lib.wxcairo
class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(None, -1, 'Hello World!')
frame.Bind(wx.EVT_PAINT, self.OnPaint)
frame.Show()
self.mainFrame = frame
return True
def OnPaint(self, evt):
# dc = wx.BufferedPaintDC(self.mainFrame)
# dc = wx.PaintDC(self.mainFrame)
# dc = wx.ClientDC(self.mainFrame)
dc = wx.WindowDC(self.mainFrame)
ctx = wx.lib.wxcairo.ContextFromDC(dc)
ctx.set_line_width(5)
ctx.move_to(10, 20)
ctx.line_to(200, 20)
ctx.stroke()
if __name__ == '__main__':
app = MyApp()
app.MainLoop()