problem binding and moving a canvas using turtle module

28 Views Asked by At

example of what i tried

I'm trying to make the drawn canvas move using the turtle module. I am assuming that it is the binding tag that is the problem but I cannot find a solution

I have tried the binding methods I could find but non of which worked.

1

There are 1 best solutions below

0
cdlane On BEST ANSWER

It's not clear to me whether you want to move the turtle window around the screen or move the drawing canvas within the turtle window. For the later we can do something like:

from tkinter import Frame, Canvas, BOTH, NW
from turtle import ScrolledCanvas, RawTurtle

class MainWindow(Frame):
    def __init__(self):
        super().__init__()
        self.pack(fill=BOTH)

        canvas = Canvas(self, width=640, height=480, bg='pink')
        canvas.pack(fill=BOTH)

        scrolled = ScrolledCanvas(canvas, width=320, height=240)

        window = canvas.create_window(50, 25, anchor=NW, window=scrolled)
        canvas.addtag_withtag('tagged', window)

        turtle = RawTurtle(scrolled)
        turtle.circle(50)

        canvas.move('tagged', 30, 30)

root = MainWindow()
root.mainloop()

Conceptual help from Python Tkinter canvas inside canvas

This sort of functionality needs to be considered from tkinter's point of view, not turtle's.

If you simply want to move the turtle's window around the screen, take a look at this answer to Change the on-screen position of the Turtle Graphics window?