I am trying to integrate the Turtle module into an interface I have created with TKInter, currently I have a canvas where I would like for the turtle to draw to (see example 1). However I am lost in how to get the draw to it.
Asked
Active
Viewed 1.3k times
5
-
3can you show us your code so far? – Joshua Nixon Jun 20 '17 at 12:54
-
Welcome to stack overflow EJ. Keep in mind we are here to help with coding problems when you get stuck. So we would need to see the code you have tried so far so we can assist with the problem. Please provide [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) so we can better assist you. – Mike - SMT Jun 20 '17 at 13:15
1 Answers
13
Try this:
import turtle
import tkinter as tk
def forward():
t.forward(100)
def back():
t.back(100)
def left():
t.left(90)
def right():
t.right(90)
root = tk.Tk()
canvas = tk.Canvas(master = root, width = 500, height = 500)
canvas.pack()
t = turtle.RawTurtle(canvas)
t.pencolor("#ff0000") # Red
t.penup() # Regarding one of the comments
t.pendown() # Regarding one of the comments
tk.Button(master = root, text = "Forward", command = forward).pack(side = tk.LEFT)
tk.Button(master = root, text = "Back", command = back).pack(side = tk.LEFT)
tk.Button(master = root, text = "Left", command = left).pack(side = tk.LEFT)
tk.Button(master = root, text = "Right", command = right).pack(side = tk.LEFT)
root.mainloop()
I have never used this module before but what I have written seems to do what you want.
References:

Tonechas
- 13,398
- 16
- 46
- 80

Joshua Nixon
- 1,379
- 2
- 12
- 25
-
1
-
1How do I change the colour of the pen? And how do I put pen up and pen down? @Joshua – Eshita Shukla Apr 26 '18 at 05:06
-
1
-
1