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 OnMouseMove(self, event):if event.Dragging() and event.LeftIsDown():x, y = self.ClientToScreen(event.GetPosition())fp = (x - self.delta[0], y - self.delta[1])self.Move(fp)def OnPaint(self, event):dc = wx.PaintDC(self)dc.SetFont(self.font)dc.SetTextForeground('WHITE')dc.DrawBitmap(self.bitmap, 0, 0, True)dc.DrawBitmap(self.cross, 170, 10, True)dc.DrawText('- Go shopping', 20, 20)dc.DrawText('- Make a phone call', 20, 50)dc.DrawText('- Write an email', 20, 80)app = wx.App()Note(None, -1, '')app.MainLoop()<strong>The</strong> idea behind creating a shaped window is simple. Mostapplications are rectangular. <strong>The</strong>y share lots of similarities.<strong>The</strong>y have menus, toolbars, titles etc. This might be boring.Some developers create more fancy applications. We canmake our applications more attractive by using images. <strong>The</strong>idea is as follows. We create a frame without a border. We candraw a custom image on the frame during the paint event.wx.Frame.__init__(self, parent, id, title,style=wx.FRAME_SHAPED |wx.SIMPLE_BORDER |wx.FRAME_NO_TASKBAR)In order to create a custom shaped application, we must setnecessary style options. <strong>The</strong> wx.FRAME_SHAPED enables tocreate a shaped window. <strong>The</strong> wx.SIMPLE_BORDER removesthe thick border. <strong>The</strong> wx.FRAME_NO_TASKBAR prevents theapplication from appearing on the taskbar.self.font = wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD, False, 'Comic Sans MS')I was looking for a nice font for the note example. I finallychose Comic Sans MS. This is a proprietary font. Linux usersmust install msttcorefonts package. If we do not have a font41 de 44 27/04/2008 1:08

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

Saved successfully!

Ooh no, something went wrong!