Unix-head needs to Windows-ize his Python script

G

gb345

I have a handy Python script, which takes a few command-line
arguments, and accepts a few options. I developed it on Unix, with
very much of a Unix-mindset. Some Windows-using colleagues have
asked me to make the script "easy to use under Windows 7". I.e.:
no command-line.

Therefore, I want to adapt my script, with the minimum amount of
work, so that it can have a double-clickable icon that brings up
a small GUI to accept command-line options (including a couple of
file-selectors for input and output files).

I am Windows-illiterate, so I really would like to keep this as
barebones as possible. Where should I look to learn more about
how to do this?

Thx!

--G

(P.S. in case it matters, it's OK to assume that Python will be
installed on the Windows system; IOW, the script need not bring
with it a Python interpreter and libraries.)
 
S

Shawn Milochik

Write a small GUI in the easy-to-use and cross-platform wxPython module. All this GUI needs to do is allow them to input the arguments. The code can then import your stand-alone version of the script and execute its code, passing the arguments in.

wxPython is just Python.
 
G

Grant Edwards

Write a small GUI in the easy-to-use and cross-platform wxPython
module. All this GUI needs to do is allow them to input the
arguments. The code can then import your stand-alone version of the
script and execute its code, passing the arguments in.
wxPython is just Python.

No, it's not.

You can't assume that any windows machine with Python installed also
has wxPython installed. The only GUI kit that you can come close to
"assuming" is Tkinter.
 
S

Shawn Milochik

No, it's not.

You can't assume that any windows machine with Python installed also
has wxPython installed. The only GUI kit that you can come close to
"assuming" is Tkinter.

I didn't mean to imply that wxPython is in the standard library. Just that you write Python code when you create a wxPython app. I apologize for the lack of clarity.

I recommended wxPython instead of Tkinter because of the opinions I've heard from other Python developers who prefer the former (I've never used Tkinter). Also, wxPython automatically looks native Mac, Windows, and Linux.

Shawn
 
G

Grant Edwards

I didn't mean to imply that wxPython is in the standard library. Just
that you write Python code when you create a wxPython app.

Ah, I see. While that is true, the same statement can be made for all
of the GUI toolkits: PyQT, PyGTK, wxPython, pyFltk, etc. When
creating a Python application using a GUI toolkit with a Python
binding, all you have to do is write Python.
I recommended wxPython instead of Tkinter because of the opinions
I've heard from other Python developers who prefer the former (I've
never used Tkinter). Also, wxPython automatically looks native Mac,
Windows, and Linux.

That's sort of true, but you've got to bundle the application
correctly on Windows to make it happen (it didn't "just work" the last
time I tried it). The OP didn't seem interested in bundling his app.

I find Tkinter is much easier to use that wxPython for simple
applications, but I generally switch to wxPython for anything more
complex that a single top-level window with a handful of widgets in
it. I also find the Tkinter API to be far more stable than wxWindows.
I've one slightly complex Tkinter application that I wrote 10 years
ago whose UI code is still running unchanged on brand new installs.

The main advantage of Tkinter is that it's the "standard" GUI library
for Python, and you can usually depend on it being installed on a
Windows machine if Python is installed. It's included in both the
"standard" Windows installer and the ActiveState windows installer.
None of the other toolkits are.

If, like the OP, you don't want to bundle up your application with a
copy of Python and GUI libraries, Tkinter is pretty much your only
option.
 
G

Grant Edwards

If using other toolkits, it's possible to compile a distributable
package with dependencies using py2exe. That way even Python need not
be installed.

http://www.py2exe.org/

But, the OP said that he could assume that Python was already
installed, that he was windows-illiterate, and that he wanted to keep
things as bare-bones as possible.

I've used wxWindows+py2exe in the past, and it can be made to work
well. But, compared to distributing a simple source file for a Tkinter
program, wxWindows+py2exe is _far_ from "bare-bones", and not
something to be casually undertaken by the windows-illiterate.
 
W

Waldemar Osuch

I have a handy Python script, which takes a few command-line
arguments, and accepts a few options.  I developed it on Unix, with
very much of a Unix-mindset.  Some Windows-using colleagues have
asked me to make the script "easy to use under Windows 7".  I.e.:
no command-line.

Therefore, I want to adapt my script, with the minimum amount of
work, so that it can have a double-clickable icon that brings up
a small GUI to accept command-line options (including a couple of
file-selectors for input and output files).

I am Windows-illiterate, so I really would like to keep this as
barebones as possible.  Where should I look to learn more about
how to do this?

Thx!

--G

(P.S. in case it matters, it's OK to assume that Python will be
installed on the Windows system; IOW, the script need not bring
with it a Python interpreter and libraries.)

Teach them "Windows key" -> Run -> cmd
or very useful "Open Command Window Here" right click option.
http://www.downloadsquad.com/2009/02/09/windows-7-tip-elevated-command-prompt-anywhere/

Failing that you may try EasyDialogs
http://www.doughellmann.com/PyMOTW/EasyDialogs/index.html

The build in module is Mac only. The Windows version is available
here.
http://www.averdevelopment.com/python/EasyDialogs.html

Waldemar
 
E

Eric Brunel

Also, wxPython automatically looks native Mac, Windows, and Linux.

And so do the recent versions of Tkinter/tcl-tk... In Python, you just
have to use the widgets in the new ttk module. These widgets also have
fewer options than their equivalent in Tkinter, so they probably are
even more accessible to people who never wrote a GUI before. The
documentation is here: http://docs.python.org/library/ttk.html#module-ttk

HTH
- Eric -
 
T

Tim Golden

I have a handy Python script, which takes a few command-line
arguments, and accepts a few options. I developed it on Unix, with
very much of a Unix-mindset. Some Windows-using colleagues have
asked me to make the script "easy to use under Windows 7". I.e.:
no command-line.

The usual suspects for this include:

http://easygui.sourceforge.net/

http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

http://www.averdevelopment.com/python/EasyDialogs.html


Any of those will suffice, I suspect. Personally, I use my
own winsys.dialogs:

http://timgolden.me.uk/python/winsys/dialogs.html

which have the very slight advantage of allowing dragging-and-dropping
files from explorer into textedit controls and/or having a button which
brings up the FileOpen (or any other) system dialog. If you do want
to use it, I suggest the svn trunk which will work for Py2 or Py3
(courtesy of 2to3).

TJG
 
U

Ulrich Eckhardt

gb345 said:
I have a handy Python script, which takes a few command-line
arguments, and accepts a few options. [...]
I want to adapt my script, with the minimum amount of
work, so that it can have a double-clickable icon that brings up
a small GUI to accept command-line options (including a couple of
file-selectors for input and output files).

I'm not sure if this is acceptable for you, but you can simply remove the
commandline stuff and simply ask the user with raw_input(). This is still a
textual UI, but it probably requires least changes. You could even add
an "--interactive" switch regardless of the target environment and then
create an MS Windows batch file that simply runs the Python script with
that switch.

Uli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top