Python 3.x 执行鼠标事件时更改光标

Python 3.x 执行鼠标事件时更改光标,python-3.x,tkinter,Python 3.x,Tkinter,如何使用Tkinter在Python中更改鼠标事件(例如右键单击)的光标?当我按下右键单击时,光标正在更改,但当我松开它时,光标不会更改 class App(Frame): def __init__(self, master=None): Frame.__init__(self, master) self.new_width=800 self.new_height=600 # Main window sel

如何使用Tkinter在Python中更改鼠标事件(例如右键单击)的光标?当我按下右键单击时,光标正在更改,但当我松开它时,光标不会更改

class App(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.new_width=800
        self.new_height=600

        # Main window
        self.fen = Tk()
        self.fen.title("Image")

        canevas = Canvas(self.fen, bd=0) ## creation of the canvas
        canevas.config(bg="white")

        canevas.config(cursor="dotbox")

        canevas.pack(fill=BOTH,expand=True) ## I place the canvas with the .pack() method

        canevas.config(scrollregion=canevas.bbox("all"))

        w=canevas.winfo_width()
        h=canevas.winfo_height()

        self.fen.update()

        # This is what enables using the mouse:
        canevas.bind("<ButtonPress-3>", self.move_start)
        canevas.bind("<B3-Motion>", self.move_move)

        # start :
    def run(self):
        self.fen.mainloop()

    #move
    def move_start(self,event):
        self.canevas.config(cursor="fleur")

    def move_move(self,event):
        self.canevas.config(cursor="fleur")
类应用程序(框架):
def uuu init uuu(self,master=None):
帧。\uuuu初始化(自,主)
自新_宽度=800
自身新高度=600
#主窗口
self.fen=Tk()
self.fen.title(“图像”)
canevas=Canvas(self.fen,bd=0)##创建画布
canevas.config(bg=“白色”)
canevas.config(cursor=“dotbox”)
canevas.pack(fill=BOTH,expand=True)##我使用.pack()方法放置画布
canevas.config(scrollregion=canevas.bbox(“全部”))
w=canevas.winfo_width()
h=canevas.winfo_高度()
self.fen.update()
#这就是允许使用鼠标的原因:
canevas.bind(“,self.move\u start)
canevas.bind(“,self.move\u move)
#开始:
def运行(自):
self.fen.mainloop()
#移动
def move_启动(自身、事件):
self.canevas.config(cursor=“fleur”)
def move_move(自身、事件):
self.canevas.config(cursor=“fleur”)

将事件绑定到按钮的释放,该按钮使用

canevas.bind("<ButtonRelease-3>", self.move_stop)
canevas.bind(“,self.move\u stop)
然后您不需要
事件,光标只会停留在
“fleur”
,直到您松开按钮



在您发布的代码中,您需要将每次提到的
canevas
替换为
self.canevas
,以便能够在
move\u start
函数(以及任何其他类方法)中引用它。

您的代码没有正确缩进。