-1
from tkinter import *
root = Tk()
def changeCursor(event, pointerName):
root.cursor(pointerName)
link = Label(root, text="Link")
link.bind("<Motion>", lambda event : changeCursor(event, "hand"))
link.pack()
root.mainloop()
我希望當光標懸停在它上面時,我的光標變成了「手」。當光標離開標籤佔用的區域時,我也想將光標改回箭頭。不過,我得到以下錯誤:如何將光標懸停在標籤上時將其改變爲手形?
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Arnob\AppData\Local\Programs\Python\Python36-
32\lib\idlelib\run.py", line 137, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Users\Arnob\AppData\Local\Programs\Python\Python36-
32\lib\queue.py", line 172, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Arnob\AppData\Local\Programs\Python\Python36-
32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "<pyshell#7>", line 1, in <lambda>
File "<pyshell#4>", line 2, in changePointer
File "C:\Users\Arnob\AppData\Local\Programs\Python\Python36-
32\lib\tkinter\__init__.py", line 2095, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'cursor'
如何改變光標變爲手形時,它是由Label佔領,然後改回爲箭頭的區域,當它離開由標籤所佔用的面積?
我認爲,所有你需要的是'鏈接= LABEL(根,文本=「鏈接」,光標= 「HAND2」)' – Goyo