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/def DrawCrossHair(self, a, b):dc = wx.ClientDC(self)dc.Clear()dc.SetPen(wx.Pen(wx.Colour(100, 100, 100), 1, wx.DOT))dc.CrossHair(a, b)<strong>The</strong> user defined method DrawCrossHair() draws the crosshair primitive. Notice that to do the drawing, we use thewx.ClientDC device context. Remember that this devicecontext should be used outside the paint event. This script is aperfect example, where we use wx.ClientDC. Not wx.PaintDC.Before we draw a new cross hair drawing, we must clear theold one. This is done with the Clear() method. It does clearthe device context area. It uses the default wx.WHITE_BRUSHbrush, unless we set a different one. We have set the windowcursor to wx.CURSOR_CROSS. In order to actually see it, wehave set the pen, which draws the cross hair, to light graycolor, 1px wide, dotted.Chech MarkCheck Mark is another simple primitive.DrawCheckMark(int x, int y, int width, int height)<strong>The</strong> DrawCheckMark() method draws a check mark on thewindow at coordinates x, y. It draws the check mark inside therectangle defined by width and height parameters.#!/usr/bin/python# checkmark.pyimport wxclass CheckMark(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)22 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!