13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> Graphics Device Interfacehttp://www.zetcode.com/wxpython/gdi/#!/usr/bin/python# line2.pyimport wxclass Line(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(250, 150))self.Bind(wx.EVT_PAINT, self.OnPaint)self.Centre()self.Show(True)def OnPaint(self, event):dc = wx.PaintDC(self)dc.DrawLine(50, 60, 190, 60)app = wx.App()Line(None, -1, 'Line')app.MainLoop()self.Bind(wx.EVT_PAINT, self.OnPaint)Here we bind the OnPaint method to the wx.PaintEvent event.It means, that each time our window is repainted, we call theOnPaint method. Now the line will not disappear, if we resizeour window (cover it, maximize it).dc = wx.PaintDC(self)Notice, that this time we have used the wx.PaintDC devicecontext.Figure: drawing a line4 de 44 27/04/2008 1:08

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!