Executing system commands with wxpython

Peter Hansen peter at engcorp.com
Fri Sep 10 13:47:09 EDT 2004


twsnnva wrote:

> Could anyone give me an example (code) of a simple program with a button
> that when clicked executes a linux shell or windows dos command like
> "ifconfig" or "ipconfig" and prints the output somewhere in the same
> window. Thanks.

Simplified example... just meets your requirements.

import wx

class MyFrame(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, -1, 'Test')
         p = wx.Panel(self, -1)

         b = wx.Button(p, 10, "A Button")
         self.Bind(wx.EVT_BUTTON, self.OnClick, b)

         self.tc = wx.StaticText(p, -1, '')
         self.tc.SetPosition((3, 25))

         self.Show(True)


     def OnClick(self, event):
         import os
         result = os.popen('ipconfig').read()
         self.tc.SetLabel(result)


if __name__ == '__main__':
     app = wx.PySimpleApp()
     frame = MyFrame()
     app.MainLoop()




More information about the Python-list mailing list