License Public Domain
Lines 34
Keywords
gui (8) Hello World (24) wx (2) wxPython (7) wxWidgets (7)
Included in this Library
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Need a quick chart or graph for your blog? Try our reStructured Text renderer. Join Siafoo Now or Learn More

wxPython hello world Atom Feed 0

In Brief This is a simple 'Hello World' example using wxPython. There may be a better way to do this. Look on the wxPython site for more information: http://wxpython.org/
# 's
 1# Uncomment these lines if you have multiple wxPython versions
2#import wxversion
3#wxversion.select('2.8')
4import wx
5
6
7class HelloWorldFrame(wx.Frame):
8 '''A simple wxPython frame'''
9
10 def __init__(self, *args, **kwargs):
11 '''Create the Frame'''
12
13 wx.Frame.__init__(self, *args, **kwargs)
14 wx.EVT_PAINT(self, self.OnPaint)
15 self.Fit()
16
17 def OnPaint(self, event):
18 ''' Draw Stuff '''
19
20 hello_world = 'Hello World!'
21
22 # Find out how big the string will be
23 extents = self.GetTextExtent(hello_world)
24
25 position_x = (self.GetSize()[0] - extents[0])/2
26 position_y = (self.GetSize()[1] - extents[1])/2
27
28 dc = wx.ClientDC(self)
29 dc.DrawText(hello_world, position_x, position_y)
30
31
32 def OnQuit(self, event=None):
33 ''' Exit '''
34
35 self.Close()
36
37if __name__ == '__main__':
38
39 app = wx.App()
40 frame = HelloWorldFrame(None, -1, 'Hello World',
41 wx.DefaultPosition,
42 wx.Size(400,400))
43
44 frame.Show()
45 app.MainLoop()

This is a simple 'Hello World' example using wxPython. There may be a better way to do this. Look on the wxPython site for more information: http://wxpython.org/