473,728 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run Python in Windows w/o popping a DOS box?

Dumb question from a Windows ignoramus:

I find myself needing to write a Python app (call it myapp.py) that
uses tkinter, which as it happens has to be used under (ugh) Windows.
That's Windows XP if it makes any difference.

I put a shortcut to myapp.py on the desktop and it shows up as a
little green snake icon, which is really cool and Pythonic. When I
double click the icon, the app launches just fine and the tkinter
interface does its thing. But Windows also launches a DOS box that
just sits on the screen uselessly. It's potentially useful in that
"print" statements in the Python app can show messages on the DOS box,
but I figure this is a graphical app so I don't plan to show messages
that way. Also, it happens I often want to run lots of instances of
the app simultaneously, and I want to launch them all by double
clicking the icon. That means the whole screen is cluttered with DOS
boxes all over the place. Of course I can minimize them by clicking
the little underscore in the corner of each one, but that really takes
away from the coolness of it all.

Question: is there any simple way to arrange to launch the app from
the desktop, without also launching a DOS box? By simple I mean
without having to mess with some complex packaging/installation system
(McMillan installer?) every time I want to modify the app, which
during development means a few hundred times a day. I have no desire
at all to conceal the source code from the user or anything like that
either.

Thanks.
Jul 19 '05 #1
17 3871
Paul Rubin skrev:
Question: is there any simple way to arrange to launch the app from
the desktop, without also launching a DOS box?


Just use the .pyw extension instead of .py, and the DOS box
automagically disappears -- or so I have been told ...
--
Leif Biberg Kristensen
http://solumslekt.org/
Jul 19 '05 #2
[Paul Rubin]
Dumb question from a Windows ignoramus:

I find myself needing to write a Python app (call it myapp.py) that
uses tkinter, which as it happens has to be used under (ugh) Windows.
That's Windows XP if it makes any difference.
Nope, the Windows flavor doesn't matter.
I put a shortcut to myapp.py on the desktop and it shows up as a
little green snake icon, which is really cool and Pythonic. When I
double click the icon, the app launches just fine and the tkinter
interface does its thing. But Windows also launches a DOS box that
just sits on the screen uselessly.
....

Question: is there any simple way to arrange to launch the app from
the desktop, without also launching a DOS box? ... From a DOS box,


ren myapp.py *.pyw

and click on a link to the resulting myapp.pyw instead. It's the
purpose of the .pyw extension on Windows not to "bring up a DOS box".
..pyw is associated with the Windows-specific pythonw.exe.
Jul 19 '05 #3
On 19 Apr 2005 20:49:56 -0700, Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote:
Dumb question from a Windows ignoramus:

I find myself needing to write a Python app (call it myapp.py) that
uses tkinter, which as it happens has to be used under (ugh) Windows.
That's Windows XP if it makes any difference.

I put a shortcut to myapp.py on the desktop and it shows up as a
little green snake icon, which is really cool and Pythonic. When I
double click the icon, the app launches just fine and the tkinter
interface does its thing. But Windows also launches a DOS box that
just sits on the screen uselessly. It's potentially useful in that
"print" statements in the Python app can show messages on the DOS box,
but I figure this is a graphical app so I don't plan to show messages
that way. Also, it happens I often want to run lots of instances of
the app simultaneously, and I want to launch them all by double
clicking the icon. That means the whole screen is cluttered with DOS
boxes all over the place. Of course I can minimize them by clicking
the little underscore in the corner of each one, but that really takes
away from the coolness of it all.

Question: is there any simple way to arrange to launch the app from
the desktop, without also launching a DOS box? By simple I mean
without having to mess with some complex packaging/installation system
(McMillan installer?) every time I want to modify the app, which
during development means a few hundred times a day. I have no desire
at all to conceal the source code from the user or anything like that
either.

Thanks.

I would try right-clicking the shortcut icon and selecting properties,
then select the shortcut tab and edit the target string with s/python/pythonw/
and then click ok.

Then try double clicking the shortcut icon again.
If that does it, you're home ;-)
If not, post more symptoms.
HTH

Regards,
Bengt Richter
Jul 19 '05 #4
bo**@oz.net (Bengt Richter) writes:
I would try right-clicking the shortcut icon and selecting
properties, then select the shortcut tab and edit the target string
with s/python/pythonw/ and then click ok.


Thanks! I'll try that tomorrow. I never would have figured that out.
Jul 19 '05 #5
Python.exe starts up a windows console which gives you things stdin,
stderr, and stdout from the C runtime.

Be warned that you do not have those things with the consoleless(?)
pythonw.exe, stuff which MS intends for gui applications.

It reminds me of select() on windows only working halfway (just
w/sockets) because of the history of how all this got added to windows.
A lot of half-way stuff.

john

Jul 19 '05 #6
bo**@oz.net (Bengt Richter) writes:
I would try right-clicking the shortcut icon and selecting
properties, then select the shortcut tab and edit the target string
with s/python/pythonw/ and then click ok.

Then try double clicking the shortcut icon again. If that does it,
you're home ;-) If not, post more symptoms.


Hmm, I clicked properties and the word python doesn't appear in the
shortcut string. The shortcut string simply points to the .py file.
I think Windows knows to run Python because of some registry entry
that maps the .py extension to python.exe. I don't know which entry
and changing it sounds a little bit dangerous.

I did see that I could select a button launch the dos box minimized,
so it doesn't clutter up the screen. That mostly solves the immediate
problem. A more complete solution (eliminate dos box altogether)
would be nice, but I can live with an auto-minimized box.

Thanks.
Jul 19 '05 #7
click on my computer
Then select tools->folder options->File Types

scroll down the where the py extension is defined, highlight it, click
on advanced
then highlight open and hit the edit button.

There you should see python.exe with some other stuff, change it to
pythonw.exe

Then, in the future, if you click on a python program, it should use
pythonw.exe
The steps should be roughly similar on different versions of windows.

I always liked the #! syntax of unix, too bad MS doesn't have it. And,
too bad their command prompt sucks, too bad process creation is heavy,
too bad . . .

Jul 19 '05 #8
On 21 Apr 2005 20:12:40 -0700, Paul Rubin <http://ph****@NOSPAM.i nvalid> wrote:
bo**@oz.net (Bengt Richter) writes:
I would try right-clicking the shortcut icon and selecting
properties, then select the shortcut tab and edit the target string
with s/python/pythonw/ and then click ok.

Then try double clicking the shortcut icon again. If that does it,
you're home ;-) If not, post more symptoms.
Hmm, I clicked properties and the word python doesn't appear in the
shortcut string. The shortcut string simply points to the .py file.

Ok, in that caseput <proper path>\pythonw.e xe in front of that.
If you need to have current working directory some place particular,
there is a "Start in" slot for that on the same property tab.
I think Windows knows to run Python because of some registry entry
that maps the .py extension to python.exe. I don't know which entry
and changing it sounds a little bit dangerous. Right, but you don't have to.
I did see that I could select a button launch the dos box minimized,
so it doesn't clutter up the screen. That mostly solves the immediate
problem. A more complete solution (eliminate dos box altogether)
would be nice, but I can live with an auto-minimized box.

As someone else suggested, you could also change the extension on your script
from .py to .pyw (and make that change in your shortcut too (or delete it
and make a new shortcut to the renamed script), or it won't find the renamed script ;-).

If you type

assoc .py

in a cmd console window, you should get what category of file the windows
registry thinks .py files are. (it uses an intermediate category classification
so that the category can be associated with a program -- e.g., many extensions
might be categorized as text files beside .txt and wind up starting notepad).
To find what's associated with the file category (sorry, type), type

ftype categoryname

For .py and .pyw on my system, you get this:

[ 8:30] C:\pywk\clp>ass oc .py
..py=Python.Fil e

[ 8:30] C:\pywk\clp>ass oc .pyw
..pyw=Python.No ConFile

[ 8:30] C:\pywk\clp>fty pe python.File
python.File=d:\ python23\python .exe "%1" %*

[ 8:30] C:\pywk\clp>fty pe python.NoConFil e
python.NoConFil e=D:\Python23\p ythonw.exe "%1" %*

To get the whole list of assocs, type it without arg
then pipe to more or window's grep aka findstr (qgrep might be avail too)

[ 8:30] C:\pywk\clp>ass oc | findstr py
..py=Python.Fil e
..pyc=Python.Co mpiledFile
..pyo=Python.Co mpiledFile

[ 8:30] C:\pywk\clp>fty pe | findstr py
Python.Compiled File=D:\Python2 3\python.exe "%1" %*
Python.File=d:\ python23\python .exe "%1" %*
Python.NoConFil e=D:\Python23\p ythonw.exe "%1" %*

(I'm not running py24 via association, and in fact rarely let the system do it,
since I need to run python explictly to pipe script input or output due to broken
windows piping in file-associated script execution on my system).

NB: If you type assoc or ftype with the "=" assignment string in format that it shows you,
(e.g. assoc .py=Python.File ) you will non-gui-wise be setting the association in the registry,
assuming you have privilege, so BE CAREFUL with that ;-)

-->> Especially don't mess with .exe association! That was tricky to recover from. (I actually
did that accidentally via Netscape's gui file association thing long ago, not from the command window ;-)

(Start>run>brow se can find you regedt32.exe and you can do anything you want
to the registry from there, if you have the information and privilege. The information
part is harder to get that privilege in most cases ;-)

BTW you can do a whole bunch of stuff in the target slot of a shortcut.
E.g., my main one to start a "DOS box" from the start menu[1] has

%SystemRoot%\sy stem32\cmd.exe /x /k prompt [$T$H$H$H$H$H$H] $P$G& d:\vc98\bin\vcv ars32.bat & home.cmd & title C++

Which starts cmd.exe with /x options and /k to keep it displayed, changes the prompt, runs the .bat script to
set environment for MSVC++, runs a little command script I made called home.cmd, which enables me easily to
come back to various project "home" directories, and sets a title in the title bar, so my window is ready to go.

A different one can set me up to use Borland's Delphi command line object pascal compiler, etc., settting
appropriate path and other environment variables, so the right set of command utilities are accessible,
and others that might have the same name are not.

[1](which uses shortcuts you can get at via start>settings> taskbar>start-menu-programs> etc)

Hm, I need to set my computer clock ...

Regards,
Bengt Richter
Jul 19 '05 #9
Wow, thanks for that very complete answer. I'll try some of those things.
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3491
by: Christian Wilcox | last post by:
Does anyone know of any existing Python implementations of an XForms viewer? Christian
63
3399
by: Stephen Thorne | last post by:
Hi guys, I'm a little worried about the expected disappearance of lambda in python3000. I've had my brain badly broken by functional programming in the past, and I would hate to see things suddenly become harder than they need to be. An example of what I mean is a quick script I wrote for doing certain actions based on a regexp, which I will simlify in this instance to make the pertanant points more relevent.
4
2611
by: Chris P. | last post by:
I've been having a problem with PythonWin that seemed to start completely spontaneously and I don't even know where to START to find the answer. The only thing I can think of that marks the point between "PythonWin works fine" and "PythonWin hardly every works fine" was that I changed the size of my Virtual Paging file, noticing that it was too small (I currently have a P4 with 1G of RAM). I tried returning it to its original (smaller)...
3
1927
by: Asad | last post by:
Hi, I am trying to write my first Windows application using VB.NET and I am having some difficulties designing the UI. Basically its one Windows Form with 4 menus on the top (no drop downs). When you click on any of the menu the UI changes. For instance clicking on the first menu shows a bunch of textboxes allowing the user to enter some information and click a button. The next menu will let user choose a file from a dropdown menu and...
52
3616
by: Steve Holden | last post by:
I've been thinking (and blogging) about python evangelism since PyCon, as a result of which I created a squidoo lens: http://www.squidoo.com/pythonlogy Imagine my surprise at discovering that this has gone up in rank (by number of views) from # 442,000 or so to #153! Clearly there's some mileage in marketing Python, and I'd like to keep the buzz going if it means more people will adopt the language.
3
2276
by: =?Utf-8?B?Zmh1bnRlcg==?= | last post by:
I have a Windows Service that should pop a windows form right before logoff, for the user to enter some information. I got things working fairly well except that the user does not get to see the form before logoff. But I know that it run properly because when I log back in the form is there and works fine. So the form opened and run, but windows was already in the "logoff" screen with no desktop showing, so I missed the form. Is there any...
2
2320
by: bappai | last post by:
Hello, I am trying to actually call a GUI from my C++ code which would have buttons and therefore can call functions from C++ again, ie extend the C++ code also. I am faced with a peculiar problem. I actually tried out an embedding code (downloaded from the net) which actually calls any function which has a text display but when I try to call any code which opens cleanly in python prompt it crashes. To make matters more concrete let me...
2
1462
by: Jean-Paul Calderone | last post by:
On Mon, 16 Jun 2008 18:11:24 +0700, Jaimy Azle <jazle@nospam.log.web.idwrote: Ah, one of those. Thanks for the clarification. That basically means your program was supposed to crash. Instead, since you had visual studio around it handled the violation by popping up a dialog and giving you the choice to continue execution, which I guess you did. There's plenty of things other than that one static variable that can get messed up in...
0
5462
by: ray007x | last post by:
I have a question for Beth Melton. Hello. This is Ray. I read an answer you graciously gave to another user about the constant popping up of "Windows Installer - Preparing to install". I cannot find anything to eliminate this headache and would be grateful for your insight and suggestions. Many people suggest running something like Windows Install Clearner (not sure that's the correct name), but on the ms website about it, we are...
0
8894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9265
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9122
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4787
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2159
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.