Hello everyone,
I am new to Python, and I have been using IDLE (v3.10.11) to run
small Python code. However, I have seen that the output scrolls to the
bottom in the output window.
Is there a way to clear the output window (something like cls in
command prompt or clear in terminal), so that output stays at the top?
Thanks in anticipation!
import os
def cls(): x=os.system("cls")
Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.
(The reason for the "x=" is: os.system returns a result, in this case
0. When you evaluate an expression in the IDE, the IDE prints the
result. So without the "x=" you get an extra line at the top of the
screen containing "0".)
On 04Jun2024 22:43, Rob Cliffe <rob.cliffe@btinternet.com> wrote:
import os
def cls(): x=os.system("cls")
Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.
(The reason for the "x=" is: os.system returns a result, in this case
0. When you evaluate an expression in the IDE, the IDE prints the
result. So without the "x=" you get an extra line at the top of the
screen containing "0".)
Not if it's in a function, because the IDLE prints the result if it
isn't None, and your function returns None. So:
def cls():
os.system("cls")
should be just fine.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 446 |
Nodes: | 16 (2 / 14) |
Uptime: | 19:30:11 |
Calls: | 9,234 |
Calls today: | 1 |
Files: | 13,494 |
Messages: | 6,063,226 |