wxPython Hello World - RMB Scripting
You appear not to have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
Get the date of every ...
If...Else on one line ...
Drop Calendar Function
Single VS Double
Understanding Variables
Latest Comments
Simple Comment System
Simple Comment System
Simple Comment System
Simple Comment System
Private Message System
Stats
Total Members: 585 [231]
Total Tutorials: 276
Newsest User: zaithstery
Todays Unique Hits: 68
Users Online: 0
 
6 Guests
Poll
Should we change our name?
Hmmmm, Yes!!
Maybe
Depends on what to
NO!
Main Content
Tutorial: wxPython Hello World By ShadowMage
Get this installed for the version of python you are using.

This quick tutorial will show you how to make a quick Hello World GUI Application in Python.

Open up IDLE or notepad, or another text editor of your choice. In this put the following:
   
CODE:
import wx

class wxPythonHelloWorld(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(200, 150), style=wx.FRAME_TOOL_WINDOW | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX)

#Main Panel
mainPanel = wx.Panel(self, -1)

#Hello World Label
helloWorld = wx.StaticText(mainPanel, -1, 'Hello World, I am a GUI\nApplication in Python', style=wx.ALIGN_CENTRE, pos=wx.Point(10, 10))
self.Centre() #Center it in the screen.
self.Show(True) #Show the app
app = wx.App()
wxPythonHelloWorld(None, -1, "Hello World!")
app.MainLoop()


That is the entire code, now we will break it down further.

   
CODE:
import wx

This will import the wxPyhon library and allow you to create the GUI applications.

   
CODE:
class wxPythonHelloWorld(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(200, 150), style=wx.FRAME_TOOL_WINDOW | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX)


This will declare a class with the default __init__ function which will initialize the frame when it is called to be opened. Doing it this way will allow you to open more than just 1 window of the same things.

   
CODE:
#Main Panel
mainPanel = wx.Panel(self, -1)

#Hello World Label
helloWorld = wx.StaticText(mainPanel, -1, 'Hello World, I am a GUI\nApplication in Python', style=wx.ALIGN_CENTRE, pos=wx.Point(10, 10))
self.Centre() #Center it in the screen.
self.Show(True) #Show the app

This code will create the main panel of the form so its not a nasty gray background. the helloWorld variable will create the static text, such as a label, on the application with the text Hello World, I am a GUI application in Python. the self.Centre, and self.Show() will center the form on your screen, then show it.

   
CODE:
app = wx.App()
wxPythonHelloWorld(None, -1, "Hello World!")
app.MainLoop()

This piece of code will create the application, then show the application with the class call. Finally, it will run the application so it all comes together and you can see it.

Note: There must be a blank line at the end of the py file or you will get an error.

Hope you learned something. If you have any questions post a comment.
Difficulty: Easy
Views: 603
Rating:
Comments
Posted on Sunday 2nd August 2009 at 04:39 AM
Adam981
all that code just to display "hello world" -.-
Posted on Sunday 2nd August 2009 at 04:34 PM
ShadowMage
That's all it was meant to do.
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Morning Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates