Python Forum
Hide command window - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Hide command window (/thread-173.html)



Hide command window - sparkz_alot - Sep-27-2016

I'm using Windows 10 and Python 3.5. Is there a way to 'hide' the command window when I run my script? The advice on line says to just change the file extension from '.py' to '.pyw' but that doesn't work (in fact the gui won't even open). I thought I saw on a youtube tut that he entered something in the if name = __main__: section, but for the life of me I can't remember the tutorial or what the entry was. Regardless, I would just like to hide the command window when I run my script. Thanks


RE: Hide command window - metulburr - Sep-27-2016

How are you running these scripts? The pyw extension gets called not by python.exe but by pythonw.exe


Most of the time you want it to provide an output for error. And if you are just giving it to friends or posting it online, then usually people make an exe in which handles the output to a file, and removes the command prompt, as well and not even require python installed in the first place.

Quote:if name = __main__: section,
This is just if your running a module itself or not. Nothing to do with hiding the console.


RE: Hide command window - sparkz_alot - Sep-27-2016

I was invoking it just by double clicking the file. Even better, I was going to put a short-cut on the desktop. Since it is a work in progress, I didn't want to have to create a new .exe each time I made a change.

Darn, I should have written down that trick :blush:


RE: Hide command window - metulburr - Sep-27-2016

Try right click on the pyw extension and choosing open with -> choose another app -> more apps -> Look for another app on this PC  (god i hate windows lol)-> navigate to your python installation and select pythonw.exe


RE: Hide command window - sparkz_alot - Sep-27-2016

(Sep-27-2016, 04:37 PM)metulburr Wrote: Try right click on the pyw extension and choosing open with -> choose another app -> more apps -> Look for another app on this PC navigate to your python installation and select pythonw.exe

Tried that, found no file association for .pyw, so I added it. No joy. On further reading, it seems the problem lies in stderr not being able to write to the console, causing a failure and exiting. I'm to lazy to fire up the Linux machine at the moment to see what happens with that.
Quote:(god i hate windows lol)->

I'm with you on that !!


RE: Hide command window - Larz60+ - Sep-28-2016

Hello,

Just an FYI, windows appears to have started a migration to Linux, or at least talking about it
Let's see how that one goes. I think they will try to make it proprietary.

Larz60+


RE: Hide command window - sparkz_alot - Sep-28-2016

(Sep-28-2016, 03:35 AM)Larz60+ Wrote: Hello,

Just an FYI, windows appears to have started a migration to Linux, or at least talking about it
Let's see how that one goes. I think they will try to make it proprietary.

Larz60+

I know in Windows 10 Anniversary Upgrade, they added a version of Ubuntu's bash command. I haven't tried it, but from what I've read it's very limited. I also read that the next version of Python (3.6) will finally fix the utf-8 debacle with Windows (here's hoping).

As to this situation, I must not be understanding the purpose of pythonw, or it's somehow broke (which is most likely the case) in my Windows. I've never used Idle, so I thought I would give it a try yesterday (there's a short-cut in the start up menu). I double-clicked it and...nothing. Looking in c:\Python 3.5\Lib\idlelib I saw there were two versions: idle.py and idle.pyw. If I run them from the command line, idle.py brings up idle. idle.pyw does nothing.

Python's docs are really quite sparse about pythonw


RE: Hide command window - metulburr - Sep-28-2016

Quote:I know in Windows 10 Anniversary Upgrade, they added a version of Ubuntu's bash command.
Quote:Just an FYI, windows appears to have started a migration to Linux, or at least talking about it

Let's see how that one goes. I think they will try to make it proprietary.

I have used cygwin for a long time. And i always add cygwin bin directory to my env variables to imitate bash commands in their command prompt. No linux user can stand navigating around with DOS commands. But it makes it quite nice as i have access to Vim, navigation, grep, or compile c/c++ ....things i use quite often, directly from their command prompt. I hate using GUI or forced to use it at least.


RE: Hide command window - wavic - Sep-29-2016

I hate Windows too

If errors are doing this trying to print in the console, just write them to a file.