How to Auto-Scroll to Top

First of all welcome @Godisgracious1031 .

And secondly, when you post code here, to make it read properly, follow this guidance: About the Python Help category. It would make a big difference if there were any loops in your code. I think you can go back and insert those markers in your original post (unless new members are restricted somehow).

Now, I see you are using ANSI escape sequences to control colour. So the obvious question is whether you could scroll the screen that way. I think you can’t.

It sounds like you make an .exe of this, and the idea is that someone should open it on their PC to display the passage. A Python program (like this) is a rather complicated and inflexible way to do that. Why not just send them a document, say HTML which they open in a browser?

If it has to be a program with a DOS window, I would take a slightly different approach, and write something that prints a certain number of lines, then pauses and waits for user input (space), before going on to the next screen-full. You could allow the user to go back a page too, or back to the top. Essentially it would behave like the command line utility more.

For that to work, you would want all the lines of the passage in a list, and a simple loop to read them out. But that is a better design anyway than all these print statements, because you could use the same program with a different passage just by changing what is in the list.

In a console application you could read that list from a file you name on the command line, but in an application canned as an .exe you’d have to find out how to bundle the text file.

1 Like