• Fwd: IDLE: clearing the screen

    From Rob Cliffe@21:1/5 to Cave Man via Python-list on Tue Jun 4 22:43:14 2024
    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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Rob Cliffe on Wed Jun 5 13:09:29 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rob Cliffe@21:1/5 to Cameron Simpson on Wed Jun 5 23:16:13 2024
    On 05/06/2024 04:09, Cameron Simpson wrote:
    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.

    Yes, you're right.
    Rob Cliffe

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)