1

I have a burning question i'd like to ask. I'm new to Python, and I wanted to know if there was a way where I could display my message, say for example

print("Hello World!")

Then right after have a message pop up, (preferably in a bolded font if possible)

input("Press Enter to Continue. . .: ")

but after pressing Enter, I want the program to delete the Message "Press Enter to Continue . . ." after it has been pressed, Is that even possible? Would that even happen? I just don't want the program to look like

Hello World!
Press Enter to Continue . . .
How are you doing today?
Press Enter to Continue . . .
This is a Test
Press Enter to Continue . . .

Any feedback is appreciated! I just started scripting so I apologize if this sounds ridiculous.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Matt Pi
  • 13
  • 1
  • 3
  • this isnt really a python issue - in that what you are trying to do is a function of a window manager running in python - you probably want to look at tkinter or another windowing package for this kind of thing – gkusner Aug 26 '14 at 16:54
  • @jonrsharpe: That's not really a duplicate. Matt doesn't want to clear the entire screen, just the last line. – Tim Pietzcker Aug 26 '14 at 16:55
  • @gkusner Thanks! I shall check out tkinter now! much appreciated. :) – Matt Pi Aug 26 '14 at 16:56
  • @TimPietzcker Yes, I'm only going for the deletion of one line. :) – Matt Pi Aug 26 '14 at 16:57
  • Which platform are you on? I'm pretty sure that the Windows console doesn't allow you to move the cursor up (at least not using ASCII control codes), but that might be different on Linux. – Tim Pietzcker Aug 26 '14 at 16:59
  • @TimPietzcker I am on Windows, I think your right about the cursor, perhaps the message is permanently there, Might I need another GUI to do my bidding? – Matt Pi Aug 26 '14 at 17:04
  • 1
    The easiest way might be to use `tkinter` to pop up a new window with the "Press Enter..." message, then delete the window, while continuing to use the console for the main output. – Mark Ransom Aug 26 '14 at 17:04
  • @MarkRansom Thanks! I shall check out how to do that now! – Matt Pi Aug 26 '14 at 17:08

1 Answers1

2

Assuming your terminal understand ANSI escape code:

print("Hello World!")
raw_input("Press Enter to Continue. . .: ")
print("\033[FX X X X X X X X X X X X X X X ");
#      ^^^^^^
#    move up
#            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#            overwrite by whatever you want
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125