Clearing the screen of IDLE interactive mode [duplicate] - python

This question already has answers here:
Any way to clear python's IDLE window?
(23 answers)
Closed 2 years ago.
Can I clear the screen of IDLE interactive mode in Windows? I tried with the following code which fails to work:
import os
os.system('cls')
The cls command works only in Windows terminal(command prompt) and it doesn't work in IDLE screen.
Is there any other way? Or first of all, is there any hope to clear that IDLE interactive mode???

cls and clear are commands which will clear a terminal (ie a DOS prompt, or terminal window). If you are using the shell within IDLE, which won't be affected by such things, a workaround might be to print a lot of empty lines with print("\n" * 100). See also this answer for more information.

No, it is not possible, neither in IDLE, nor in Python command prompt.
Use IPython instead with its “magic” command %cls (and many others), preferable as a part of some IDE which utilized it, for example Spyder, PyCharm or JupyterLab.
Anaconda contains both Spyder and JupyterLab and many Python packages, it's probably the best all-in-one solution.

You can from os import system and then system("cls")
this will just clear out the screen. have fun coding:).

Related

Pycharm not importing standard library [duplicate]

This question already has answers here:
Difference Between Python's IDLE and its command line
(4 answers)
Closed 1 year ago.
But they work just fine in IDLE. For example,
import time
time.asctime()
works fine in IDLE, but is not working in Pycharm.
I have tried changing the interpreter but still doesn't work. Other packages that I installed myself from cmd like numpy are working fine.
Any help will be appreciated
EDIT : When I add the package time by pressing + in the interpreter settings, it says
ERROR: Could not find a version that satisfies the requirement time
If you get no error message, and you have shown us your whole program then your problem is that you are expecting time.asctime() on its own to produce output the way it does in IDLE.
But to get the same effect in a program that PyCharm runs, you need something like print(time.asctime()).
To get PyCharm to do what IDLE does in this case, you need to ask PyCharm to open a Python console.

No rectangle shown in pygame [duplicate]

This question already has answers here:
Problems getting pygame to show anything but a blank screen on Macos
(10 answers)
Closed 2 years ago.
Just started programming in python and pygames.
Whenever I try running a py file with pygames, the pygames window will appear, but there will be absolutely nothing in it. No errors in the log, but nothing shows, it's just a gray screen.
I tried running it on IDLE, and through the command line (I'm on a mac so I use the terminal)
And it's not just my programs that aren't showing anything, I've tried to run one of pygames examples, and it will still not display anything. For example, if I run the pygames alien example, the window will appear with a blank gray background. I'll hear the audio for the program, but no display.
Anything would help, I'm at a loss especially since no errors are showing in the log.
EDIT1:
I'm using Python 3 (and I really need to keep using Python 3)
EDIT2:
I'm using python 3.7. pygames version 1.9.4. The examples are with the pygames, they were downloaded together, so I assume it's for that version.
EDIT3:
ok, my OS is Mojave 10.14. I've tried starting the application by: opening the file, running it on IDLE, and running it through the command line, none have worked. python2 is installed, but when I run the pygame it's a python3 file
Known issue with Mojave - see their issue tracking: https://github.com/pygame/pygame/issues/555
You can also install new pygame using pip install pygame=2.0.0.dev6. This
worked in my case.

Python in VSCode: How do you run a previous command?

I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!

How to get rid of "Command Line" window when running Python script with GUI? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I hide the console window in a PyQt app running on Windows?
I am programming under Python2.6 + PyQT + Eric4 environment.
All the GUI and Program parts are done, but here is the problem.
When I run my program, two windows pop up.
One is the window (or frame) I want, the other is like a python interpretor window having a all black undergroud color. And I really don't want this to show.
What can I do to get rid of it?
Please help me out of this.
I suppose you are using Windows, the only operating system I know to open a prompt when you double click a script. There are two solutions AFAIK: execute the file with the pythonw.exe executable, as suggested by #Adrien. If you save the file with the .pyw extension, Windows automatically uses pythonw.exe for executing the script when you double click
on windows, you can get rid of the console window by using pythonw.exe to run your script (instead of the standard python.exe)
(i don't know if there is a similar difference on other operating systems)
On Windows, the program window only pops up if you save your python file with the extension .py instead of .pyw.

how to clear the screen in python [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
clear terminal in python
How to clear python interpreter console?
I'm trying to write a program in Python but I don't know how to clear the screen.
I use both Windows and Linux and I use commands to clear the screen in those, but I don't know how to do it in Python.
How do I use Python to clear the screen?
If you mean the screen where you have that interpreter prompt >>> you can do CTRL+L on Bash shell can help. Windows does not have equivalent. You can do
import os
os.system('cls') # on windows
or
os.system('clear') # on linux / os x

Categories

Resources