Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #387: Your computer's union contract is set to expire at midnight.


comp / comp.lang.python / Re: IDLE: clearing the screen

SubjectAuthor
* IDLE: clearing the screenCave Man
`- Re: IDLE: clearing the screenStefan Ram

1
Subject: IDLE: clearing the screen
From: Cave Man
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Tue, 4 Jun 2024 13:34 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: caveman@example.invalid (Cave Man)
Newsgroups: comp.lang.python
Subject: IDLE: clearing the screen
Date: Tue, 4 Jun 2024 19:04:17 +0530
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v3n54p$en04$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 04 Jun 2024 15:34:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="68a1e6bc3543b09b9c5a634121e71843";
logging-data="482308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/g/9jdyqDLgMzv23KnlY+53nayeHdrrw0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:3emaQ2wK4YHfCaKkNIj6la7wV3w=
Content-Language: en-US
View all headers

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!

Subject: Re: IDLE: clearing the screen
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Tue, 4 Jun 2024 14:19 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: IDLE: clearing the screen
Date: 4 Jun 2024 14:19:01 GMT
Organization: Stefan Ram
Lines: 78
Expires: 1 Feb 2025 11:59:58 GMT
Message-ID: <console-20240604151710@ram.dialup.fu-berlin.de>
References: <v3n54p$en04$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Ie5x6R+fiuU26mxBA84hLgbKPmytHzBUGn5DMylk1h2afH
Cancel-Lock: sha1:FXhaxmnlv3brtmky7TB7anyOtl4= sha256:hRsbjBI0TblZuqRRpk5Mw3u+DOHChFI1E2ksihXH/7c=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Cave Man <caveman@example.invalid> wrote or quoted:
>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?

No, unless you patch IDLE to add such a feature!

(When I wrote [4] here recently, I had thought of just such cases!)

But you can implement a console yourself using tkinter.

As a motivating example see [1]. But as a beginner you may
not be able to modify [1] for your needs unless you learn
some tkinter first, for that I recommend [2] and [3].

[1]

import time
import tkinter as tk

class TextWrapper:
def __init__(self, master):
self.master = master
self.text = tk.Text(master)
self.text.pack()

def print( self, line: str )-> None:
"""Append a line to the Text component."""
self.text.insert( tk.END, line + "\n" )
self.text.see( tk.END ) # Scroll to the end

def reset( self )->None:
"""Clear the Text component."""
self.text.delete( 1.0, tk.END )

def put( line: str )-> None:
text_wrapper.print( line ); root.update(); time.sleep( 1 )

def cls()-> None:
text_wrapper.reset(); root.update(); time.sleep( 1 )

def execute_after_one_second():
put( "Hello, World!" )
put( "This is a test." )
put( "Another line." )

cls()

put( "Text has been reset." )

root = tk.Tk()
text_wrapper = TextWrapper(root)
root.after( 1000, execute_after_one_second )
root.mainloop()

[2]

the GUI part of "Programming Python" by Mark Lutz

[3]

"Python Tkinter" or "Modern Tkinter for Busy Python
Developers" by Mark Roseman
(He has a good tkinter tutorial on his web site)

[4]

We need somethin like a portable curses module (plus colorama)
and it has got to work on both Windoze and Linux straight out
of the box in standard Python. And it would be even sicker if it
could run in that IDLE console too! That way, we could code up
some legit terminal-based software (like slrn or Nethack) using
just plain ol' Python, no extra stuff required. It's a real
shame it ain't already part of the standard library. Someone's
got to step up and make this happen. Python needs a portable
console TUI!

1

rocksolid light 0.9.8
clearnet tor