Is there a way to clear the "Run" console in PyCharm? I want a code that delete/hide all the print() made previously. Like the "clear_all" button, but without having to press it manually.
I have read that there is a way to do it in a terminal with os.system("cls"), but in PyCharm, it only adds a small square without clearing anything.
Also, I don't want to use print("\n" *100) since I don't want to be able to scroll back and see the previous prints.
Just click the trash can icon to the left of the command window and it clears the command history!
In Pycharm:
CMD + ,
(or Pycharm preferences);CTRL + L
or anything)Easy Method: Shortcut: Control K, Right click on terminal and clear Buffer
This question is a bit old but I thought I would leave this here for other people who are wondering how to do this
How to
Download this package https://github.com/asweigart/pyautogui. It allows python to send key strokes.
You may have to install some other packages first
Set a keyboard shortcut for clearing the run window in pycharm as explained by Taylan Aydinli
Then if you set the keyboard shortcut for 'clear all' to
Command + L
use this in your python scriptExample program
This will clear the screen after the user types an input.
EDIT: If you aren't focused on the tool window then your clear hot-key won't work, you can see this for yourself if you try pressing your hot-key while focused on, say, the editor, you won't clear the embedded terminals contents.
PyAutoGUI has no way of focusing on windows directly, to solve this you can try to find the coordinate where the run terminal is located and then send a left click to focus, if you don't already know the coordinates where you can click your mouse you can find it out with the following code:
An example of output:
and now the actual code:
You could just do a ("\n" * 100000000), so it'll be impossible to scroll back.