TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: ALL
from: DENNIS LEE BIEBER
date: 2017-10-22 13:10:00
subject: Re: Screen control

On Sun, 22 Oct 2017 14:34:31 +0100, T M Smith
 declaimed the following:

> I am altering a python program and just wish to display readings of
>temperature etc. in the same place on screen after each update.
>
 You'd probably get better suggestions by showing the relevant snippet
of existing code.

 Since your original post implies the existing program is scrolling, I'm
going to assume it is a simple console application (I don't see anyone
going through the effort of creating a GUI application with a scrolling
output, where a single line text widget would suffice).

-=-=-=-=-
"""
    Simple demo for scroll vs non-scroll
    (Python 2.7, hence xrange and paren-less print)
"""

import sys
import time

if "scroll" in sys.argv:
    print
    print
    for x in xrange(100):
        print "Pseudo-Temperature: %10.3f" % (x * 3.14159 - 25.5)
        time.sleep(1)
elif "overwrite" in sys.argv:
    print
    print
    for x in xrange(100):
        sys.stdout.write("\rPseudo-Temperature: %10.3f"
                         % (x * 3.14159 - 25.5))
        time.sleep(1)
else:
    print "\nPlease supply either 'scroll' or 'overwrite' on the command
line"


-=-=-=-=-
C:\Users\Wulfraed\Documents\Python Progs>so.py

Please supply either 'scroll' or 'overwrite' on the command line

C:\Users\Wulfraed\Documents\Python Progs>so scroll


Pseudo-Temperature:    -25.500
Pseudo-Temperature:    -22.358
Pseudo-Temperature:    -19.217
Pseudo-Temperature:    -16.075
Pseudo-Temperature:    -12.934
Pseudo-Temperature:     -9.792
Pseudo-Temperature:     -6.650
Pseudo-Temperature:     -3.509
Pseudo-Temperature:     -0.367
Pseudo-Temperature:      2.774
Pseudo-Temperature:      5.916
Pseudo-Temperature:      9.057
Pseudo-Temperature:     12.199
Traceback (most recent call last):
  File "C:\Users\Wulfraed\Documents\Python Progs\so.py", line 14, in

    time.sleep(1)
KeyboardInterrupt

C:\Users\Wulfraed\Documents\Python Progs>so overwrite


Pseudo-Temperature:     21.624Traceback (most recent call last):
  File "C:\Users\Wulfraed\Documents\Python Progs\so.py", line 21, in

    time.sleep(1)
KeyboardInterrupt

C:\Users\Wulfraed\Documents\Python Progs>

{I killed the runs after a few seconds}

 There is no control as to which line is updated -- the I/O takes place
on whatever line the cursor/console is at when running. I used the %f
formatting to set a fixed width for the output; otherwise one risks have a
short value not overwrite the rest of a long value.
--
 Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.