简体   繁体   English

如何更改鼠标指针颜色tkinter?

[英]how to change the mouse pointer color tkinter?

is there a way to change the mouse color in Tkinter? 有没有办法在Tkinter中更改鼠标颜色? I have a dark background and the mouse never shows over the Tkinter window. 我有一个黑暗的背景,鼠标永远不会显示在Tkinter窗口上。

You can change the cursor using the cursor option on the root window . 您可以使用根窗口上的光标选项更改光标。 To change the color, eg, 要改变颜色,例如,

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. 有些符号和颜色对我有用,有些则不适用于linux,尽管该选项应该与操作系统无关。 For example, 'clock' and 'gumby' work, 'pirate' does not (but fails quietly, without throwing an error). 例如,'clock'和'gumby'工作,'pirate'没有(但是安静地失败,没有抛出错误)。

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 . 请注意,如果您想要更改插入光标, 请参阅此处 ,但请参阅 tldr insertbackground Note that you may be using a cursor that doesn't support changing colors, in which case try a different cursor 请注意,您可能正在使用不支持更改颜色的光标,在这种情况下尝试使用其他光标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM