Differences between revisions 3 and 4
Revision 3 as of 2006-04-23 00:47:54
Size: 897
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 4 as of 2008-03-11 10:50:26
Size: 897
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Introduction

It's really easy to use command-line arguments in your app. Import sys and in your subclass of wxApp, just use sys.argv.

Code Sample

import wx
import sys

class MyApp(wx.App):
    def OnInit(self):
        args = sys.argv[1:]
        frame = wx.Frame(None, -1, "args = %s" % (args,))
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

Then, at the command prompt:

prompt:chmod +x tmp.py
prompt:./tmp.py test

Comments

Or, for more complex handling, use the Python getopt or optparse modules. - JohnFouhy

Comments

On Windows's command prompt, only

python UsingCommandLineArguments.py opt1 opt2

works, but not the direct call:

UsingCommandLineArguments.py opt1 opt2

- Franz Steinhaeusler

UsingCommandLineArguments (last edited 2008-03-11 10:50:26 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.