在终端屏幕上隐藏鼠标光标的Python程序
编写一个程序来隐藏终端屏幕上的鼠标光标。
方法:
- C语言导入curses包用于此任务,调用napms函数进行延时,调用curs_set()函数使光标消失。
- 在Python中,导入并使用了一个名为 UniCurses 的包,它类似于 curses 包。程序中使用sleep()函数进行延时,调用curs_set()函数使光标消失,然后再次出现。
下面是上述方法的实现:
Python3
# 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()
输出:
运行程序后,会出现一个新窗口:
2 秒后,鼠标光标消失:
4 秒后,鼠标光标再次出现:
6 秒后,程序结束: