How to change the color and symbol of the cursor in Tkinter?
Tkinter is a standard GUI library for Python. It provides various widgets for GUI development. We can give background color to widgets as per choice. But, sometimes background color affects mouse pointer visibility. In such cases, changing the cursor color makes the mouse pointer distinguishable. The color of the cursor can be changed by specifying the color with the cursor type. These values can be specified in the cursor attribute while creating the widget or can be specified using config() method for that widget. Cursor type and cursor color if not defined for widget inherits from the parent window. Cursor colors can be specified with their standard names or with hexadecimal RGB values. For example, cursor=”plus red” or cursor=”plus #FF0000″, will provide plus cursor icon with red color.
For some cursors, it is possible to provide 2 colors, fill color and border color. For example, cursor=”dot red blue”, will provide a dot cursor icon with red color bordered by blue color.
- Create a Tkinter window
- Specify cursor icon and color for the window using cursor parameter
- Specify cursor icon and color for other widgets while creating them or using config method for that widget.
The following program demonstrates the change in colors of the cursor and also a change in the cursor for top-level window and other widgets.
Note: Changing cursor color in Tkinter is not supported in Windows. For available cursors list can refer here.
We can change text cursor color using insertbackground parameter for text widget. Following program demonstrates text cursor color change.