更改 Tkinter 中的滑鼠遊標
Tkinter 是一個基於 GUI 的 Python 庫,用於開發各種型別的功能性和基於 GUI 的應用程式。它提供了許多函式和方法,可用於在開發應用程式時提供可擴充套件性和各種功能。
在本文中,我們將瞭解如何使用 cursor 屬性在 Tkinter 框架中的按鈕上懸停時更改滑鼠遊標。Tkinter 的按鈕庫中提供了大量游標對映,可為終端使用者提供不同的視覺效果。庫中的一些游標為:
"arrow"
"circle"
"clock"
"cross"
"dotbox"
"exchange"
"fleur"
"heart"
"heart"
"man"
"mouse"
"pirate"
"plus"
"shuttle"
"sizing"
"spider"
"spraycan"
"star"
"target"
"tcross"
"trek"
"watch"
讓我們先建立一些按鈕,然後將其中一些游標應用到滑鼠指標上。
示例
from tkinter import * #Create an instance of window or frame win= Tk() #Set the geometry win.geometry("700x600") win.resizable(0,0) win.config(cursor= "fleur") #Let us create a text label Label(win, text= "Hover on each of these buttons", font=('Poppins', 20)).pack(pady=20) #Create some buttons with cursor property b1= Button(win, text= "Star",cursor="star") b1.pack(pady=20) b2= Button(win, text= "Arrow",cursor="arrow") b2.pack(pady=20) b3= Button(win, text= "Circle",cursor="circle") b3.pack(pady=20) b4= Button(win, text= "Clock",cursor="clock") b4.pack(pady=20) b5= Button(win, text= "Heart",cursor="heart") b5.pack(pady=20) b6= Button(win, text= "Man",cursor="man") b6.pack(pady=20) b7= Button(win, text= "Mouse",cursor="mouse") b7.pack(pady=20) #Keep Running the window win.mainloop()
輸出
執行以上程式碼將建立帶有不同滑鼠指標形狀的不同按鈕。
廣告