简体   繁体   English

Python Tkinter更改光标的颜色

[英]Python Tkinter Changing the Colour of a Cursor

In my code I'm creating a gui that has various different buttons in it, and I have assigned cursors to each. 在我的代码中,我正在创建一个gui,其中包含各种不同的按钮,并且我已经为每个按钮指定了游标。 What I'm wondering is how to change the colour of the cursor from the default white when hovered over these buttons. 我想知道的是如何在悬停在这些按钮上时将光标的颜色从默认白色更改。

B1 = Button(root, text='Delete Recording', bg = col1, cursor = "dotbox", width=15, command=killthat)

When hovered over, this turns the cursor into a dotbox. 当盘旋时,这会将光标变成一个点框。

I have tried adding colours like so 我试过添加这样的颜色

cursor = "dotbox brown1"

It doesn't produce an error, but it doesn't change the colour either. 它不会产生错误,但也不会改变颜色。

Im running on Windows 7 if that helps. 我在Windows 7上运行,如果这有帮助。

Tkinter supports cursor colors, but it could be that it's not supported on windows 7. I don't have a windows box to test on, but the following creates a green cursor on linux: Tkinter支持光标颜色,但可能是它在Windows 7上不受支持。我没有要测试的Windows框,但是下面在linux上创建了一个绿色光标:

import tkinter as tk
root = tk.Tk()
root.configure(cursor="dotbox green")
root.mainloop()

"brown1" may not be a valid color. “brown1”可能不是有效颜色。 At least on linux it's not. 至少在linux上它不是。 Have you tried an rgb value (eg: cursor="dotbox #ff0000" )? 你试过一个rgb值(例如: cursor="dotbox #ff0000" )?

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

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