+ 1
How do i write a code that slides across the screen?
14 Answers
+ 5
Do you mean to animate on the console, something like this?
https://code.sololearn.com/cny2exUQ1N8M/?ref=app
It cannot be done on Sololearn. But study how my functions printR and printL work to move text rightward or leftward, then take a look at using the curses library for printing at (x, y) locations on the screen:
https://docs.python.org/3/howto/curses.html
+ 3
There is a simple approach that works on some consoles. You can use '\r' (carriage return, ASCII 13) to send the cursor back to the beginning of the line. Then overwrite the whole line, using spaces as needed to place the text in its new position and overwrite the previous one.
Some consoles are configured to act on '\r' by also adding a linefeed, so this approach might not work. Sololearn's consoles are configured that way.
+ 2
What do you mean by sliding over the screen?
By screen, do you mean the console or a user interface window?
+ 1
Thanks
+ 1
Console output is static.
+ 1
It's totally possible, just treat it like normal film with frames. Every "frame" is a new cleared screen. In every iteration add blank text " " or new line "\n" to make it appear moving. Give it also some pause between "frames" to see anything (because normally it would all be done in nanoseconds), and Voilà.
import time
import os
for x in range(20):
print(x*'\n'+x*" "+"text")
time.sleep(1)
os.system('clear')
It just doesn't work on sololearn, but you can easily check it on any other IDE like pycharm or pydroid 3 for Android. (both are free)
0
Console
0
Can you give an example output?
0
I want the output to have the string sliding across
0
Console output is static.
0
So u cannot have it moving around?
0
No. You can try to make something similar by outputting the string in a loop and slightly changing the position in the line, like:
like
like
like
0
How can I do this?
0
On each iteration of the loop, add some blank spaces before the string