[Python] Is there a way to change draw order for existing shapes in Tkinter canvas ( over a...

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting a video stream using socket, and displaying it on a canvas. I am attempting to have a box that can be moved using sliders to position over a certain object in frame. the issue is I'm not redrawing the shape i guess, so it's getting drawn under the stream. is there any way around this? should i double layer a canvas in the grid so it's drawn on top?

    self.tempImage = self.tempImage.resize((int(self.videoWidth),int(self.videoHeight)),Image.Resampling.LANCZOS)
    self.photo = ImageTk.PhotoImage(image = self.tempImage)
    self.VideoCanvas.create_image(0, 0, image = self.photo, anchor = tk.NW)
    if len(self.BBox) == 0:
    self.BBox.append(self.VideoCanvas.create_rectangle(self.xVar.get() - 5,self.yVar.get()-5,self.xVar.get()+5,self.yVar.get()+5))
    else:
    self.VideoCanvas.coords(self.BBox[0],self.xVar.get() - 5,self.yVar.get()-5,self.xVar.get()+5,self.yVar.get()+5)


    xVar and yVar are the linked IntVar for the sliders, i'm trying to make it somewhat scalable so it's a bit messy

    Continue reading...

Compartilhe esta Página