“Stop” Button in Tkinter












-2















I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far:



import turtle
import tkinter as tk
def start():
t.forward(100)
t.right(90)
t.forward(100)
t.left(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)

def stop():
t.stop

def clear():
canvas.delete("all")

root = tk.Tk()
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


Also the clear button works but afterwards the start button doesn't work anymore. If someone can help me with that as well.



Thank you to @Mike - SMT for helping me with this code. Here's the edited and fully functioning code:



import turtle
import tkinter as tk


def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1


running = True

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
t.reset()
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)


root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()









share|improve this question




















  • 1





    Possible duplicate of How Do You Make Python Turtle Stop Moving?

    – Mike - SMT
    Nov 15 '18 at 18:52











  • There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

    – Mike - SMT
    Nov 15 '18 at 18:54











  • None of those resolve my problem.

    – Pokyzard
    Nov 15 '18 at 18:57











  • They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

    – Mike - SMT
    Nov 15 '18 at 19:00











  • So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

    – Pokyzard
    Nov 15 '18 at 19:03
















-2















I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far:



import turtle
import tkinter as tk
def start():
t.forward(100)
t.right(90)
t.forward(100)
t.left(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)

def stop():
t.stop

def clear():
canvas.delete("all")

root = tk.Tk()
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


Also the clear button works but afterwards the start button doesn't work anymore. If someone can help me with that as well.



Thank you to @Mike - SMT for helping me with this code. Here's the edited and fully functioning code:



import turtle
import tkinter as tk


def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1


running = True

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
t.reset()
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)


root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()









share|improve this question




















  • 1





    Possible duplicate of How Do You Make Python Turtle Stop Moving?

    – Mike - SMT
    Nov 15 '18 at 18:52











  • There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

    – Mike - SMT
    Nov 15 '18 at 18:54











  • None of those resolve my problem.

    – Pokyzard
    Nov 15 '18 at 18:57











  • They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

    – Mike - SMT
    Nov 15 '18 at 19:00











  • So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

    – Pokyzard
    Nov 15 '18 at 19:03














-2












-2








-2








I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far:



import turtle
import tkinter as tk
def start():
t.forward(100)
t.right(90)
t.forward(100)
t.left(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)

def stop():
t.stop

def clear():
canvas.delete("all")

root = tk.Tk()
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


Also the clear button works but afterwards the start button doesn't work anymore. If someone can help me with that as well.



Thank you to @Mike - SMT for helping me with this code. Here's the edited and fully functioning code:



import turtle
import tkinter as tk


def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1


running = True

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
t.reset()
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)


root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()









share|improve this question
















I'm trying to have a turtle animation start with a button and stop with a button. It's very easy to start with a button but I can't seem to be able to figure out a stop button? Here's my code so far:



import turtle
import tkinter as tk
def start():
t.forward(100)
t.right(90)
t.forward(100)
t.left(90)
t.forward(100)
t.right(90)
t.forward(100)
t.right(90)
t.forward(100)

def stop():
t.stop

def clear():
canvas.delete("all")

root = tk.Tk()
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


Also the clear button works but afterwards the start button doesn't work anymore. If someone can help me with that as well.



Thank you to @Mike - SMT for helping me with this code. Here's the edited and fully functioning code:



import turtle
import tkinter as tk


def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1


running = True

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
t.reset()
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)


root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()






python tkinter turtle-graphics tkinter-canvas






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 18:42







Pokyzard

















asked Nov 15 '18 at 18:46









PokyzardPokyzard

62




62








  • 1





    Possible duplicate of How Do You Make Python Turtle Stop Moving?

    – Mike - SMT
    Nov 15 '18 at 18:52











  • There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

    – Mike - SMT
    Nov 15 '18 at 18:54











  • None of those resolve my problem.

    – Pokyzard
    Nov 15 '18 at 18:57











  • They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

    – Mike - SMT
    Nov 15 '18 at 19:00











  • So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

    – Pokyzard
    Nov 15 '18 at 19:03














  • 1





    Possible duplicate of How Do You Make Python Turtle Stop Moving?

    – Mike - SMT
    Nov 15 '18 at 18:52











  • There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

    – Mike - SMT
    Nov 15 '18 at 18:54











  • None of those resolve my problem.

    – Pokyzard
    Nov 15 '18 at 18:57











  • They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

    – Mike - SMT
    Nov 15 '18 at 19:00











  • So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

    – Pokyzard
    Nov 15 '18 at 19:03








1




1





Possible duplicate of How Do You Make Python Turtle Stop Moving?

– Mike - SMT
Nov 15 '18 at 18:52





Possible duplicate of How Do You Make Python Turtle Stop Moving?

– Mike - SMT
Nov 15 '18 at 18:52













There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

– Mike - SMT
Nov 15 '18 at 18:54





There are a few post on how to stop the turtle. These post: How to stop the python turtle from drawing, Start and stop Python turtle with space bar, How Do You Make Python Turtle Stop Moving?.

– Mike - SMT
Nov 15 '18 at 18:54













None of those resolve my problem.

– Pokyzard
Nov 15 '18 at 18:57





None of those resolve my problem.

– Pokyzard
Nov 15 '18 at 18:57













They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

– Mike - SMT
Nov 15 '18 at 19:00





They are the same question. You are not able to stop in between drawing because any even you would use to stop cant run until the function has ended. You will need to break up the drawing into sections and check a tracking variable.

– Mike - SMT
Nov 15 '18 at 19:00













So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

– Pokyzard
Nov 15 '18 at 19:03





So I can't stop the animation with a button? I need to have a start and stop button for my project :/ welp

– Pokyzard
Nov 15 '18 at 19:03












2 Answers
2






active

oldest

votes


















0














You cannot stop each draw statement unless you provide a checker in between each line drawn.



The below code is just a rough mock up of how you could make something to check for a tracking variable used to tell it to no longer draw new lines.



The closest thing you can do to being able to stop drawing is something like this:



import turtle
import tkinter as tk

def start():
global tracker
tracker = False
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.left(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)


def stop():
global tracker
tracker = True

def clear():
canvas.delete("all")

root = tk.Tk()
tracker = False
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


This will at least stop drawing after each line but you cannot stop mid line draw.



Just for the fun of it if we add some tracking variables and use some cleaner logic we can start, stop and start again.



Update: From @cdlane's comment below I have added addition tracking and updated the clear function. This should allow for start stop start without issues and also be able to clear the field.



import turtle
import tkinter as tk

def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
canvas.delete("all")
tracker = False
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)

root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()





share|improve this answer


























  • In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

    – cdlane
    Nov 16 '18 at 18:09











  • @cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

    – Mike - SMT
    Nov 16 '18 at 19:54











  • @cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

    – Mike - SMT
    Nov 16 '18 at 20:16













  • Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

    – cdlane
    Nov 16 '18 at 23:37











  • @cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

    – Mike - SMT
    Nov 17 '18 at 0:12



















0














I agree with the ideas in @Mike-SMT's answer but I'd go about it a different way. The turtle and its controls seem very much like a Python generator to me so I've recast it as such. The turtle moves along a path, one pixel at a time, yielding control which may, or may not return. Or it may exhaust its path and stop the iteration:



import tkinter as tk
from turtle import RawTurtle

PATH = [(100.00, 0.00), (100.00, -100.00), (200.00, -100.00), (200.00, -200.00), (100.00, -200.00)]

def run():
for position in PATH:
turtle.setheading(turtle.towards(position))

while turtle.distance(position) > 1:
turtle.forward(1)
yield

def start():
global generator, running

running = True

while running:
try:
next(generator)

except ValueError: # user clicked start but already running
return

except TypeError: # new run
turtle.reset()
generator = run()

except StopIteration: # end of complete run
generator = None
running = False
break

def stop():
global running
running = False

def clear():
global generator
turtle.reset()
generator = None

root = tk.Tk()
canvas = tk.Canvas(width=500, height=500)
canvas.pack()

turtle = RawTurtle(canvas, "turtle")

running = True
generator = None

tk.Button(text="Start", command=start).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Stop", command=stop).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Clear", command=clear).pack(side=tk.LEFT, expand=tk.TRUE)

root.mainloop()



Also the clear button works but afterwards the start button doesn't
work anymore. If someone can help me with that as well.




You can replace your current clear() function with:



def clear():
t.clear()


if you just want to erase the path that's been drawn but leave the turtle where it ended up. If you want to erase the path and reset the turtle back to the starting point, instead do:



def clear():
t.reset()





share|improve this answer


























  • I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

    – Pokyzard
    Nov 19 '18 at 18:32











  • @Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

    – cdlane
    Nov 20 '18 at 0:43













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326052%2fstop-button-in-tkinter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You cannot stop each draw statement unless you provide a checker in between each line drawn.



The below code is just a rough mock up of how you could make something to check for a tracking variable used to tell it to no longer draw new lines.



The closest thing you can do to being able to stop drawing is something like this:



import turtle
import tkinter as tk

def start():
global tracker
tracker = False
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.left(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)


def stop():
global tracker
tracker = True

def clear():
canvas.delete("all")

root = tk.Tk()
tracker = False
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


This will at least stop drawing after each line but you cannot stop mid line draw.



Just for the fun of it if we add some tracking variables and use some cleaner logic we can start, stop and start again.



Update: From @cdlane's comment below I have added addition tracking and updated the clear function. This should allow for start stop start without issues and also be able to clear the field.



import turtle
import tkinter as tk

def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
canvas.delete("all")
tracker = False
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)

root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()





share|improve this answer


























  • In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

    – cdlane
    Nov 16 '18 at 18:09











  • @cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

    – Mike - SMT
    Nov 16 '18 at 19:54











  • @cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

    – Mike - SMT
    Nov 16 '18 at 20:16













  • Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

    – cdlane
    Nov 16 '18 at 23:37











  • @cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

    – Mike - SMT
    Nov 17 '18 at 0:12
















0














You cannot stop each draw statement unless you provide a checker in between each line drawn.



The below code is just a rough mock up of how you could make something to check for a tracking variable used to tell it to no longer draw new lines.



The closest thing you can do to being able to stop drawing is something like this:



import turtle
import tkinter as tk

def start():
global tracker
tracker = False
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.left(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)


def stop():
global tracker
tracker = True

def clear():
canvas.delete("all")

root = tk.Tk()
tracker = False
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


This will at least stop drawing after each line but you cannot stop mid line draw.



Just for the fun of it if we add some tracking variables and use some cleaner logic we can start, stop and start again.



Update: From @cdlane's comment below I have added addition tracking and updated the clear function. This should allow for start stop start without issues and also be able to clear the field.



import turtle
import tkinter as tk

def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
canvas.delete("all")
tracker = False
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)

root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()





share|improve this answer


























  • In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

    – cdlane
    Nov 16 '18 at 18:09











  • @cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

    – Mike - SMT
    Nov 16 '18 at 19:54











  • @cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

    – Mike - SMT
    Nov 16 '18 at 20:16













  • Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

    – cdlane
    Nov 16 '18 at 23:37











  • @cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

    – Mike - SMT
    Nov 17 '18 at 0:12














0












0








0







You cannot stop each draw statement unless you provide a checker in between each line drawn.



The below code is just a rough mock up of how you could make something to check for a tracking variable used to tell it to no longer draw new lines.



The closest thing you can do to being able to stop drawing is something like this:



import turtle
import tkinter as tk

def start():
global tracker
tracker = False
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.left(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)


def stop():
global tracker
tracker = True

def clear():
canvas.delete("all")

root = tk.Tk()
tracker = False
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


This will at least stop drawing after each line but you cannot stop mid line draw.



Just for the fun of it if we add some tracking variables and use some cleaner logic we can start, stop and start again.



Update: From @cdlane's comment below I have added addition tracking and updated the clear function. This should allow for start stop start without issues and also be able to clear the field.



import turtle
import tkinter as tk

def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
canvas.delete("all")
tracker = False
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)

root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()





share|improve this answer















You cannot stop each draw statement unless you provide a checker in between each line drawn.



The below code is just a rough mock up of how you could make something to check for a tracking variable used to tell it to no longer draw new lines.



The closest thing you can do to being able to stop drawing is something like this:



import turtle
import tkinter as tk

def start():
global tracker
tracker = False
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.left(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)
if tracker == False:
t.right(90)
if tracker == False:
t.forward(100)


def stop():
global tracker
tracker = True

def clear():
canvas.delete("all")

root = tk.Tk()
tracker = False
canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)

tk.Button(text = "Start", command = start).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)

root.mainloop()


This will at least stop drawing after each line but you cannot stop mid line draw.



Just for the fun of it if we add some tracking variables and use some cleaner logic we can start, stop and start again.



Update: From @cdlane's comment below I have added addition tracking and updated the clear function. This should allow for start stop start without issues and also be able to clear the field.



import turtle
import tkinter as tk

def start(turtle_object, draw_path):
global tracker, start_ndex, end_ndex, started
tracker = False
if started == False:
started = True
for i in range(start_ndex, end_ndex):
if tracker == False and i <= end_ndex:
pth = draw_path[i]
if pth[0] == "f":
turtle_object.forward(pth[1])
elif pth[0] == "r":
turtle_object.right(pth[1])
elif pth[0] == "l":
turtle_object.left(pth[1])
start_ndex += 1

def stop():
global tracker, started
tracker = True
started = False

def clear():
global t, tracker, started, start_ndex
canvas.delete("all")
tracker = False
start_ndex = 0
started = False
t = turtle.RawTurtle(canvas)

root = tk.Tk()
tracker = False
start_ndex = 0
started = False # added this tracking variable to prevent issues with spamming the start button.

draw_path = [["f", 100], ["r", 90], ["f", 100], ["l", 90], ["f", 100], ["r", 90], ["f", 100], ["r", 90], ["f", 100]]


end_ndex = len(draw_path)

canvas = tk.Canvas(width = 500, height = 500)
canvas.pack()

t = turtle.RawTurtle(canvas)
tk.Button(text = "Start", command = lambda: start(t, draw_path)).pack(side = tk.LEFT)
tk.Button(text = "Stop", command = stop).pack(side = tk.LEFT)
tk.Button(text = "Clear", command = clear).pack(side = tk.LEFT)
root.mainloop()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 20:16

























answered Nov 15 '18 at 19:05









Mike - SMTMike - SMT

9,26221034




9,26221034













  • In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

    – cdlane
    Nov 16 '18 at 18:09











  • @cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

    – Mike - SMT
    Nov 16 '18 at 19:54











  • @cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

    – Mike - SMT
    Nov 16 '18 at 20:16













  • Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

    – cdlane
    Nov 16 '18 at 23:37











  • @cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

    – Mike - SMT
    Nov 17 '18 at 0:12



















  • In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

    – cdlane
    Nov 16 '18 at 18:09











  • @cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

    – Mike - SMT
    Nov 16 '18 at 19:54











  • @cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

    – Mike - SMT
    Nov 16 '18 at 20:16













  • Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

    – cdlane
    Nov 16 '18 at 23:37











  • @cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

    – Mike - SMT
    Nov 17 '18 at 0:12

















In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

– cdlane
Nov 16 '18 at 18:09





In your restartable solution, there are a couple of issues. First, it shares the "can't recover from 'clear'" issue of the OP's original. Second, if you're fast enough to click 'Start' multiple times during the run, the turtle goes astray. Not nit-picking, just interested to see how you'd handle problems I ran into in my own solution.

– cdlane
Nov 16 '18 at 18:09













@cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

– Mike - SMT
Nov 16 '18 at 19:54





@cdlane I agree there are limitations to my solutions. I will see if I can come up with a better solutions to contend with the other issues.

– Mike - SMT
Nov 16 '18 at 19:54













@cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

– Mike - SMT
Nov 16 '18 at 20:16







@cdlane I have updated my 2nd solution to contend with the issues you mentioned. I imaging I could probably build something cleaner but sometimes quick and dirty does the trick :D

– Mike - SMT
Nov 16 '18 at 20:16















Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

– cdlane
Nov 16 '18 at 23:37





Nice -- it runs solidly now! The turtle library keeps an internal list of turtles that it has created, so they are effectively never garbage collected. Better to reuse turtles, if you can, than allocate new ones. This is with respect to your clear() method.

– cdlane
Nov 16 '18 at 23:37













@cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

– Mike - SMT
Nov 17 '18 at 0:12





@cdlane Hum. I never used turtle before and was not aware of how it remembers each turtle. What would you do in this case?

– Mike - SMT
Nov 17 '18 at 0:12













0














I agree with the ideas in @Mike-SMT's answer but I'd go about it a different way. The turtle and its controls seem very much like a Python generator to me so I've recast it as such. The turtle moves along a path, one pixel at a time, yielding control which may, or may not return. Or it may exhaust its path and stop the iteration:



import tkinter as tk
from turtle import RawTurtle

PATH = [(100.00, 0.00), (100.00, -100.00), (200.00, -100.00), (200.00, -200.00), (100.00, -200.00)]

def run():
for position in PATH:
turtle.setheading(turtle.towards(position))

while turtle.distance(position) > 1:
turtle.forward(1)
yield

def start():
global generator, running

running = True

while running:
try:
next(generator)

except ValueError: # user clicked start but already running
return

except TypeError: # new run
turtle.reset()
generator = run()

except StopIteration: # end of complete run
generator = None
running = False
break

def stop():
global running
running = False

def clear():
global generator
turtle.reset()
generator = None

root = tk.Tk()
canvas = tk.Canvas(width=500, height=500)
canvas.pack()

turtle = RawTurtle(canvas, "turtle")

running = True
generator = None

tk.Button(text="Start", command=start).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Stop", command=stop).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Clear", command=clear).pack(side=tk.LEFT, expand=tk.TRUE)

root.mainloop()



Also the clear button works but afterwards the start button doesn't
work anymore. If someone can help me with that as well.




You can replace your current clear() function with:



def clear():
t.clear()


if you just want to erase the path that's been drawn but leave the turtle where it ended up. If you want to erase the path and reset the turtle back to the starting point, instead do:



def clear():
t.reset()





share|improve this answer


























  • I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

    – Pokyzard
    Nov 19 '18 at 18:32











  • @Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

    – cdlane
    Nov 20 '18 at 0:43


















0














I agree with the ideas in @Mike-SMT's answer but I'd go about it a different way. The turtle and its controls seem very much like a Python generator to me so I've recast it as such. The turtle moves along a path, one pixel at a time, yielding control which may, or may not return. Or it may exhaust its path and stop the iteration:



import tkinter as tk
from turtle import RawTurtle

PATH = [(100.00, 0.00), (100.00, -100.00), (200.00, -100.00), (200.00, -200.00), (100.00, -200.00)]

def run():
for position in PATH:
turtle.setheading(turtle.towards(position))

while turtle.distance(position) > 1:
turtle.forward(1)
yield

def start():
global generator, running

running = True

while running:
try:
next(generator)

except ValueError: # user clicked start but already running
return

except TypeError: # new run
turtle.reset()
generator = run()

except StopIteration: # end of complete run
generator = None
running = False
break

def stop():
global running
running = False

def clear():
global generator
turtle.reset()
generator = None

root = tk.Tk()
canvas = tk.Canvas(width=500, height=500)
canvas.pack()

turtle = RawTurtle(canvas, "turtle")

running = True
generator = None

tk.Button(text="Start", command=start).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Stop", command=stop).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Clear", command=clear).pack(side=tk.LEFT, expand=tk.TRUE)

root.mainloop()



Also the clear button works but afterwards the start button doesn't
work anymore. If someone can help me with that as well.




You can replace your current clear() function with:



def clear():
t.clear()


if you just want to erase the path that's been drawn but leave the turtle where it ended up. If you want to erase the path and reset the turtle back to the starting point, instead do:



def clear():
t.reset()





share|improve this answer


























  • I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

    – Pokyzard
    Nov 19 '18 at 18:32











  • @Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

    – cdlane
    Nov 20 '18 at 0:43
















0












0








0







I agree with the ideas in @Mike-SMT's answer but I'd go about it a different way. The turtle and its controls seem very much like a Python generator to me so I've recast it as such. The turtle moves along a path, one pixel at a time, yielding control which may, or may not return. Or it may exhaust its path and stop the iteration:



import tkinter as tk
from turtle import RawTurtle

PATH = [(100.00, 0.00), (100.00, -100.00), (200.00, -100.00), (200.00, -200.00), (100.00, -200.00)]

def run():
for position in PATH:
turtle.setheading(turtle.towards(position))

while turtle.distance(position) > 1:
turtle.forward(1)
yield

def start():
global generator, running

running = True

while running:
try:
next(generator)

except ValueError: # user clicked start but already running
return

except TypeError: # new run
turtle.reset()
generator = run()

except StopIteration: # end of complete run
generator = None
running = False
break

def stop():
global running
running = False

def clear():
global generator
turtle.reset()
generator = None

root = tk.Tk()
canvas = tk.Canvas(width=500, height=500)
canvas.pack()

turtle = RawTurtle(canvas, "turtle")

running = True
generator = None

tk.Button(text="Start", command=start).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Stop", command=stop).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Clear", command=clear).pack(side=tk.LEFT, expand=tk.TRUE)

root.mainloop()



Also the clear button works but afterwards the start button doesn't
work anymore. If someone can help me with that as well.




You can replace your current clear() function with:



def clear():
t.clear()


if you just want to erase the path that's been drawn but leave the turtle where it ended up. If you want to erase the path and reset the turtle back to the starting point, instead do:



def clear():
t.reset()





share|improve this answer















I agree with the ideas in @Mike-SMT's answer but I'd go about it a different way. The turtle and its controls seem very much like a Python generator to me so I've recast it as such. The turtle moves along a path, one pixel at a time, yielding control which may, or may not return. Or it may exhaust its path and stop the iteration:



import tkinter as tk
from turtle import RawTurtle

PATH = [(100.00, 0.00), (100.00, -100.00), (200.00, -100.00), (200.00, -200.00), (100.00, -200.00)]

def run():
for position in PATH:
turtle.setheading(turtle.towards(position))

while turtle.distance(position) > 1:
turtle.forward(1)
yield

def start():
global generator, running

running = True

while running:
try:
next(generator)

except ValueError: # user clicked start but already running
return

except TypeError: # new run
turtle.reset()
generator = run()

except StopIteration: # end of complete run
generator = None
running = False
break

def stop():
global running
running = False

def clear():
global generator
turtle.reset()
generator = None

root = tk.Tk()
canvas = tk.Canvas(width=500, height=500)
canvas.pack()

turtle = RawTurtle(canvas, "turtle")

running = True
generator = None

tk.Button(text="Start", command=start).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Stop", command=stop).pack(side=tk.LEFT, expand=tk.TRUE)
tk.Button(text="Clear", command=clear).pack(side=tk.LEFT, expand=tk.TRUE)

root.mainloop()



Also the clear button works but afterwards the start button doesn't
work anymore. If someone can help me with that as well.




You can replace your current clear() function with:



def clear():
t.clear()


if you just want to erase the path that's been drawn but leave the turtle where it ended up. If you want to erase the path and reset the turtle back to the starting point, instead do:



def clear():
t.reset()






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 0:41

























answered Nov 16 '18 at 2:48









cdlanecdlane

17.6k21144




17.6k21144













  • I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

    – Pokyzard
    Nov 19 '18 at 18:32











  • @Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

    – cdlane
    Nov 20 '18 at 0:43





















  • I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

    – Pokyzard
    Nov 19 '18 at 18:32











  • @Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

    – cdlane
    Nov 20 '18 at 0:43



















I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

– Pokyzard
Nov 19 '18 at 18:32





I tried this command but there were some problems with indents (the 'return') which I tried fixing by replacing return with turtle.reset() but then there were problems with 'generator' not being defined in the line Next(generator) .

– Pokyzard
Nov 19 '18 at 18:32













@Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

– cdlane
Nov 20 '18 at 0:43







@Pokyzard, an indentation oddity did creep in so I fixed and reloaded the example code. I did a copy of it from this web page and paste into a file without using an editor in between and it runs fine. Give it another try. (I assume you're using Python 3 based on your import of tkinter with a lower 't'.)

– cdlane
Nov 20 '18 at 0:43




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326052%2fstop-button-in-tkinter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]