如何在 Tkinter 中更改滑鼠指標顏色?
Tkinter 是用於開發基於 GUI 的應用程式的 Python 標準庫。我們可以透過使用內建函式和方法來更改其小元件的屬性。在某些應用程式中,這些屬性也會影響滑鼠指標。
Tkinter 為我們提供了一種更改視窗中滑鼠指標顏色的方法。要配置滑鼠指標顏色,我們可以使用(游標型別及其顏色)來指定游標值。例如,要更改標籤小元件中的游標顏色,我們可以將值指定為 cursor="plus #aab1212",其中 "plus" 定義了游標型別,#aab1212 是顏色的十六進位制值。
示例
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add bottom widget
label=Label(win, text="label cursor", cursor="plus red", font=('calibri 18'))
label.pack(pady=20)
Button(win, text="Button cursor",cursor="dot blue").pack()
win.mainloop()輸出
如果我們執行以上程式碼,它將顯示一個帶有一個標籤小元件和一個按鈕的視窗。將滑鼠懸停在小元件上將更改游標屬性。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP