Python program to hide the mouse cursor on the Terminal screen

Write a program to hide the mouse cursor on the terminal screen.

Approach:

  • The curses package is imported and used for this task in C language, napms function call is used for the delay, and curs_set() function is called to make the cursor disappear.
  • In Python, a package called UniCurses, which is similar to the curses package, is imported and used. In the program, the sleep() function is used for the delay and the curs_set() function is called to make the cursor disappear and then appear again.

Below is the implementation of the above approach:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program for the above approach
import curses
import time
  
# Initializing curses 
stdscr = curses.initscr()
  
# Setting the cursor to visible by 
# inserting 1 as argument
curses.curs_set(1)  
  
# Delay of 2 seconds
time.sleep(2)
  
# Setting the cursor to invisible by 
# inserting 0 as argument
curses.curs_set(0
  
# Delay of 2 seconds
time.sleep(2)
  
# Setting the cursor to visible by 
# inserting 1 as argument
curses.curs_set(1)  
  
# Delay of 2 seconds
time.sleep(2)
  
# Restoring terminal to it's
# original state
curses.endwin()

chevron_right


Output:
After running the program, a new window appears:



After 2 seconds, the mouse cursor disappears:

After 4 seconds, the mouse cursor appears again:

After 6 seconds, the program ends:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.