0

This isn't my actual code but it is just an example. How do I make it my code wait but stay on the same line?

    import pygame
    pygame.init()

    print("Hi")
    pygame.time.wait(1000)
    print(".")
    pygame.time.wait(500)
    print(".")
    pygame.time.wait(500)
    print(".")
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Wait for user's input or simply during execution? – qqqqq Oct 17 '21 at 02:12
  • 3
    `print(".", end="")` ? – sj95126 Oct 17 '21 at 02:15
  • 2
    Does this answer your question? [multiple prints on the same line in Python](https://stackoverflow.com/questions/5598181/multiple-prints-on-the-same-line-in-python) – Michael Wheeler Oct 17 '21 at 02:26
  • do you really need `pygame` for this? Why not `time.sleep`?. And if you write game in `PyGame` then using `wait` is not good idea if you run `event loop` to get key/mouse events. – furas Oct 17 '21 at 06:03

1 Answers1

2

The default end to a print() statement in python is '\n' (new line). As @sj95126 mentions in his comment, you will want to replace this ending with an empty string. Fortunately, Python gives a simple way of doing this:

print("Hi", end="")
pygame.time.wait(1000)
print(".", end="")
pygame.time.wait(500)
print(".", end="")
pygame.time.wait(500)
print(".")

The above code will print:

Hi...

Similarly, if you wanted to make every line end in a comma, you could do:

print("A", end=",")
pygame.time.wait(1000)
print("B", end=",")
pygame.time.wait(500)
print("C", end=",")
pygame.time.wait(500)
print("Bye")

Which would print:

A,B,C,Bye

Sal
  • 302
  • 1
  • 11