I have a Python script that sends output to a DOS command window (I am using Windows 7) using the print() function, but I would like to prevent (or hide) the cursor from blinking at the next available output position. Has anyone any idea how I can do this? I have looked at a list of DOS commands but I cannot find anything suitable.
Any help would be appreciated. Alan
I've been writing a cross platform colour library to use in conjunction with colorama for python3. To totally hide the cursor on windows or linux:
import sys
import os
if os.name == 'nt':
import msvcrt
import ctypes
class _CursorInfo(ctypes.Structure):
_fields_ = [("size", ctypes.c_int),
("visible", ctypes.c_byte)]
def hide_cursor():
if os.name == 'nt':
ci = _CursorInfo()
handle = ctypes.windll.kernel32.GetStdHandle(-11)
ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
ci.visible = False
ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))
elif os.name == 'posix':
sys.stdout.write("\033[?25l")
sys.stdout.flush()
def show_cursor():
if os.name == 'nt':
ci = _CursorInfo()
handle = ctypes.windll.kernel32.GetStdHandle(-11)
ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci))
ci.visible = True
ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci))
elif os.name == 'posix':
sys.stdout.write("\033[?25h")
sys.stdout.flush()
The above is a selective copy & paste. From here you should pretty much be able to do what you want. Assuming I didn't mess up the copy and paste this was tested under Windows Vista and Linux / Konsole.