+ 1

How do i write a code that slides across the screen?

26th Apr 2022, 5:29 PM
Uttam
14 Réponses
+ 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
27th Apr 2022, 4:34 AM
Brian
Brian - avatar
+ 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.
28th Apr 2022, 7:52 PM
Brian
Brian - avatar
+ 2
What do you mean by sliding over the screen? By screen, do you mean the console or a user interface window?
26th Apr 2022, 5:34 PM
Lisa
Lisa - avatar
+ 1
Thanks
26th Apr 2022, 6:15 PM
Uttam
+ 1
Console output is static.
28th Apr 2022, 10:30 AM
Bushra Aboubida
Bushra Aboubida - avatar
+ 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)
28th Apr 2022, 4:54 PM
Piotr Ś
Piotr Ś - avatar
0
Console
26th Apr 2022, 5:41 PM
Uttam
0
Can you give an example output?
26th Apr 2022, 5:44 PM
Lisa
Lisa - avatar
0
I want the output to have the string sliding across
26th Apr 2022, 5:51 PM
Uttam
0
Console output is static.
26th Apr 2022, 5:52 PM
Lisa
Lisa - avatar
0
So u cannot have it moving around?
26th Apr 2022, 5:53 PM
Uttam
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
26th Apr 2022, 5:57 PM
Lisa
Lisa - avatar
0
How can I do this?
26th Apr 2022, 5:58 PM
Uttam
0
On each iteration of the loop, add some blank spaces before the string
26th Apr 2022, 5:59 PM
Lisa
Lisa - avatar