how to clear python console in pycharm

Solutions on MaxInterview for how to clear python console in pycharm by the best coders in the world

showing results for - "how to clear python console in pycharm"
Homer
26 Jul 2019
1This question is a bit old but I thought I would leave this here for other people who are wondering how to do this
2
3How to
4
5Download this package https://github.com/asweigart/pyautogui. It allows python to send key strokes.
6
7You may have to install some other packages first
8
9If you are installing PyAutoGUI from PyPI using pip:
10
11Windows has no dependencies. The Win32 extensions do not need to be installed.
12
13OS X needs the pyobjc-core and pyobjc module installed (in that order).
14
15Linux needs the python3-xlib (or python-xlib for Python 2) module installed. Pillow needs to be installed, and on Linux you may need to install additional libraries to make sure Pillow's PNG/JPEG works correctly. See:
16
17Set a keyboard shortcut for clearing the run window in pycharm as explained by Taylan Aydinli
18
19CMD + , (or Pycharm preferences);
20
21Search: "clear all"; Double click ->
22
23Add keyboard shortcut (set it to CTRL + L or anything)
24
25Enjoy this new hot key in your Pycharm console!
26
27Then if you set the keyboard shortcut for 'clear all' to Command + L use this in your python script
28
29import pyautogui
30pyautogui.hotkey('command', 'l')
31Example program
32
33This will clear the screen after the user types an input.
34
35EDIT: 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.
36
37PyAutoGUI 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:
38
39import pyautogui
40from time import sleep
41sleep(2)
42print(pyautogui.position())
43An example of output:
44
45(2799, 575)
46and now the actual code:
47
48import pyautogui
49
50while True:
51    input_1 = input("?")
52    print(input_1)
53    pyautogui.click(x=2799, y=575)
54    pyautogui.hotkey('command', 'l')