using python drag & drop selected image segment
As said in the comments:
Indentation is important!
Within the Example-class its initiation method this entire code-block is misaligned:
startframe = tk.Frame(root)canvas = tk.Canvas(startframe,width=1280,height=720)startframe.pack()canvas.pack()one = tk.PhotoImage(file=r'images/test1.gif')root.one = one # to prevent the image garbage collected.canvas.create_image((0,0), image=one, anchor='nw',tags="img1")self.canvas.tag_bind("img1", "<1>", self.on_token_press1)self.canvas.tag_bind("img1", "<1>", self.on_token_release1)self.canvas.tag_bind("token", "<B1-Motion>", self.on_token_motion1)
If I simply add a Tab
to the indentation of the entire block I was able to run the OP's code without any problem.
Since the script requires a GIF
file to be placed in images/test1.gif
I downloaded and used this GIF:
tkinter doesn't seem to actually play the gif (which isn't asked by the OP), but it does indeed show it.