Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

python - how to change the mouse pointer color tkinter?

is there a way to change the mouse color in Tkinter? I have a dark background and the mouse never shows over the Tkinter window.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can change the cursor using the cursor option on the root window. To change the color, e.g.,

root = tk.Tk()
root.config(cursor='clock red red')

Some symbols and colors work for me, some don't, on linux, although the option should be operating system agnostic. For example, 'clock' and 'gumby' work, 'pirate' does not (but fails quietly, without throwing an error).

Ironically, boat is supported on my machine, but pirates are not. Probably a good call not to support both

In response to comment

Sometimes you need to call this on sub-widgets, if their default behaviour is to overwrite it. For example

root = tk.Tk()
root.config(cursor='gumby red red')
text=tk.Text(root)
text.pack()
# oh no cursor is boring again! That makes sense, the default
# text cursor is slightly different than the root cursor
text.config(cursor='boat blue blue') # phew!

Note that if instead you wanted to change the insertion cursor, see here, but tldr insertbackground. Note that you may be using a cursor that doesn't support changing colors, in which case try a different cursor


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...