Programs saved as file with .py extension in Python programming language terminology is called Modules. Once you create a module and save it and when you double click the python file icon to open, it will not remain open. You will see a blink of black program window which closes automatically. You will experience a flash pop up and closing of console window.

So how do we stop this? How do we keep the window open? There is a simple way. Just add a input statement at the end. Doing this will keep the program window open because python expects that some input at this point. Say your program is called helloworld.py and the content of the file is just a print statement-

print("Hello World!")

When you save the program as helloworld.py and afterwards when you click on the helloworld.py icon, you will see a flash of window pop up which closes immediately. To make the window remain open, just add a input( ) statement like-


print("Hello World!")
input( )

Now when you click the helloworld.py file icon the window will remain open for you to view.


See the following video demonstration:




0 comments:

Post a Comment

 
Top