Python Forum
Hide command window
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hide command window
#1
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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#2
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.
Recommended Tutorials:
Reply
#3
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:
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
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
Recommended Tutorials:
Reply
#5
(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 !!
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
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+
Reply
#7
(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
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#8
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.
Recommended Tutorials:
Reply
#9
I hate Windows too

If errors are doing this trying to print in the console, just write them to a file.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 471 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] command require close window Krissstian 14 2,924 Nov-19-2022, 04:18 PM
Last Post: Krissstian
  [Tkinter] Hide clicked buttons Rubberduck 6 3,520 Jun-02-2021, 12:44 PM
Last Post: Rubberduck
  tkinter window and turtle window error 1885 3 6,698 Nov-02-2019, 12:18 PM
Last Post: 1885
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,290 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  General help with hide show status bar for a begineer in python ArakelTheDragon 0 2,776 Mar-17-2019, 11:58 AM
Last Post: ArakelTheDragon
  Hide button when clicked frequency 2 8,764 Dec-24-2018, 02:10 PM
Last Post: frequency
  [PyGUI] Hi All, how to hide/mask user input in PySimpleGUI nmrt 1 14,914 Sep-21-2018, 09:59 AM
Last Post: nmrt
  [PYQT5] Crashing when using .hide() and .show() aking76 0 7,330 Sep-18-2018, 02:09 PM
Last Post: aking76
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 10,487 Jun-12-2018, 08:05 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020