Sigel Alex
Sigel Alex

Reputation: 17

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

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()

Upvotes: 0

Views: 75

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386352

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.

Upvotes: 1

Related Questions