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!