Drawing a point on a Label that is on top of a canvas

Question:

Label (there is an image) is located on the canvas throughout the volume. How can I put dots on top of label (they are apparently placed on canvas, but the image overlaps them. For example, I gave the interface of my program and circled the right placeenter image description here

Please help me, I’ve been sitting with this problem for a long time, I can’t get away from Label I need to use it. I also get the coordinates of the points from the picture, but you can’t draw on the label

import tkinter as tk
from PIL import Image
from PIL import ImageTk


class interface:

    def __init__(self, root):
        self.root = root
        self.panelA = None
        self.f1 = tk.Frame(self.root,)
        self.f1.grid()
        self.canvas2 = tk.Canvas(self.f1, height=610, width=1050,)
        self.canvas2.grid(row=0, column=0)

    def select_image(self):
        image = Image.open("Graf/Ag8.png")
        resize_image = image.resize((1050, 610))
        image = ImageTk.PhotoImage(resize_image)
        self.panelA = tk.Label(self.f1, image=image)
        self.panelA.bind("<Button-1>", self.callback)
        self.panelA.image = image
        self.panelA.grid(row=0, column=0)


    def callback(self, event):
        print(event.x, event.y)


def main():
    root = tk.Tk()
    obj_interface = interface(root)
    obj_interface.select_image()
    root.mainloop()


if __name__ == '__main__':
    main()
Asked By: Sigel Alex

||

Answers:

Label (there is an image) is located on the canvas throughout the volume. How can I put dots on top of label

You cannot draw on top of widgets embedded in a canvas. If you’re using a Label just to embed an image, you can instead create an image object using the canvas method create_image. You can then draw items on top of the image.

Answered By: Bryan Oakley
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.