Re: Fwd: IDLE: clearing the screen

2024-06-05 Thread Rob Cliffe via Python-list



On 05/06/2024 04:09, Cameron Simpson wrote:

On 04Jun2024 22:43, Rob Cliffe  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.


Yes, you're right.
Rob Cliffe

--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: IDLE: clearing the screen

2024-06-04 Thread Cameron Simpson via Python-list

On 04Jun2024 22:43, Rob Cliffe  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.
--
https://mail.python.org/mailman/listinfo/python-list


Fwd: IDLE: clearing the screen

2024-06-04 Thread Rob Cliffe via Python-list

Welcome to Python!  A great language for program development.

Answers might be platform-dependent (are you using WIndows, Linux, etc.).
However, the following works for me on WIndows.  You can put it in the 
startup.py file so you don't have to type it every time you start up the 
IDLE.


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".)


I am sure that some jiggery-pokery could be used so you don't have to 
type the "()".  But that's more advanced ...


Best wishes
Rob Cliffe


On 04/06/2024 14:34, Cave Man via Python-list wrote:

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!


--
https://mail.python.org/mailman/listinfo/python-list