Creating Frame in wxPython


Note:Use “portable python” IDE since it has wxPython by default.

import wx                      //importing the core package of wxPython

class MyApp(wx.App):           //creating a class "MyApp" instantiating the "wx.App" 
 def OnInit(self):             //constructor for the class
     myframe=wx.Frame(parent=None,title="A sample Frame")  //creating a frame(parent,title)
     myframe.Show()             //set the frame to be visible
     return True               //true if the constructor runs without errors else return false implicitly
//-------------end of the class------------------
myapp=MyApp()                  //creating an instance of MyApp class
myapp.MainLoop()               //starting a loop for dispatching  events.


This is the output

A simple frame

NOTE:Make sure you indent your python codes properly before running to prevent compilation errors!

Installing Python the easy way

Instead of downloading the Python from the official site,download the portable version of Python 2.6 which comes with several modules such wxPython(GUI programming ) , Iron Python(For C# ) ,pyGame …


Download Python IDE from this link

Do not download Python 3.0.1 at least for now.Python 2.6 is enough for most of the tasks.