Start New Discussion within our Software Development Community

This small code example shows you how to approach the beginning concept of an very simple "IDE" for Python.

the beginning of an very simple "IDE" for Python
tested with Python27 and wxPython291 by vegaseat  15jan2013

import wx
import subprocess

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)

        s = "Enter your Python script below:"
        self.label = wx.StaticText(self, wx.ID_ANY, s)
        self.edit = wx.TextCtrl(self, wx.ID_ANY,
            size=(300, 180), style=wx.TE_MULTILINE)

        self.result = wx.TextCtrl(self, wx.ID_ANY,
            size=(300, 180), style=wx.TE_MULTILINE)

        s = "Run Python27"
        self.button = wx.Button(self, wx.ID_ANY, label=s)
        # bind mouse event to an action
        self.button.Bind(wx.EVT_BUTTON, self.button_click)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        flag1 = wx.LEFT|wx.TOP|wx.RIGHT|wx.EXPAND
        vsizer.Add(self.label, 0, flag=flag1, border=10)
        vsizer.Add(self.edit, 0, flag=flag1, border=10)
        vsizer.Add(self.button, 0, flag=flag1, border=10)
        vsizer.Add(self.result, 0, flag=flag1, border=10)

    def button_click(self, event):
        """run Python button has been clicked"""
        code_str = self.edit.GetValue()
        # save the code
        # uses working directory (improve this!)
        filename = ""
        with open(filename, "w") as fout:

        # command to execute Python (use correct path)
        run_python = "C:/Python27/python.exe -u " + filename
        # execute the code and pipe the result to a string
        process = subprocess.Popen(run_python, shell=True,
        # wait till completed
        # optional check 0 --> success
        # read the result to a string
        result_str =
        # display the result

app = wx.App(0)
frame = MyFrame(None, 'The Almost IDE', (320, 500))
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.