Python _tkinter.TclError from root.mainloop() after calling root.destroy()












0















Why do I get an error with my tkinter mainloop() about a invalid command name canvas? I am creating an AI board game, and I created a main loop. I use 2 lists for my checker id's, black_id, and white_id, just not portrayed here:



def main_game_AI():
print("Read the README file first to learn how to move.")
move = input("What do you move?:")
checker_move = int(move)
where = input("What direction will you move?:")
canvas.move(black_id[checker_move],-23,-50)
print("Robot: OOOOOOoooooh!! Tricky decision! I play:")
canvas.move(white_id[3], -23,50)
white3 = 18
print("We start with the",first_side,"side.")
while gameOn == True:
main_game_AI()
root.destroy()
root.mainloop()


In my loop, main_game_AI() runs, then I run the root.mainloop() for the tkinter gui to work. But I must use root.destroy(), so the loop continues. This works well for the first iteration. But when I put in the test inputs for the second iteration, I got the following error:



Traceback (most recent call last):
File "chineseCheckersAI.py", line 86, in <module>
main_game_AI()
File "chineseCheckersAI.py", line 77, in main_game_AI
canvas.move(black_id[checker_move],-23,-50)
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 2588, in move
self.tk.call((self._w, 'move') + args)
_tkinter.TclError: invalid command name ".!canvas"









share|improve this question

























  • Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

    – Bryan Oakley
    Nov 14 '18 at 8:42













  • Yes, but then, i can't update the canvas.

    – F. Zeng
    Nov 15 '18 at 5:10
















0















Why do I get an error with my tkinter mainloop() about a invalid command name canvas? I am creating an AI board game, and I created a main loop. I use 2 lists for my checker id's, black_id, and white_id, just not portrayed here:



def main_game_AI():
print("Read the README file first to learn how to move.")
move = input("What do you move?:")
checker_move = int(move)
where = input("What direction will you move?:")
canvas.move(black_id[checker_move],-23,-50)
print("Robot: OOOOOOoooooh!! Tricky decision! I play:")
canvas.move(white_id[3], -23,50)
white3 = 18
print("We start with the",first_side,"side.")
while gameOn == True:
main_game_AI()
root.destroy()
root.mainloop()


In my loop, main_game_AI() runs, then I run the root.mainloop() for the tkinter gui to work. But I must use root.destroy(), so the loop continues. This works well for the first iteration. But when I put in the test inputs for the second iteration, I got the following error:



Traceback (most recent call last):
File "chineseCheckersAI.py", line 86, in <module>
main_game_AI()
File "chineseCheckersAI.py", line 77, in main_game_AI
canvas.move(black_id[checker_move],-23,-50)
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 2588, in move
self.tk.call((self._w, 'move') + args)
_tkinter.TclError: invalid command name ".!canvas"









share|improve this question

























  • Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

    – Bryan Oakley
    Nov 14 '18 at 8:42













  • Yes, but then, i can't update the canvas.

    – F. Zeng
    Nov 15 '18 at 5:10














0












0








0








Why do I get an error with my tkinter mainloop() about a invalid command name canvas? I am creating an AI board game, and I created a main loop. I use 2 lists for my checker id's, black_id, and white_id, just not portrayed here:



def main_game_AI():
print("Read the README file first to learn how to move.")
move = input("What do you move?:")
checker_move = int(move)
where = input("What direction will you move?:")
canvas.move(black_id[checker_move],-23,-50)
print("Robot: OOOOOOoooooh!! Tricky decision! I play:")
canvas.move(white_id[3], -23,50)
white3 = 18
print("We start with the",first_side,"side.")
while gameOn == True:
main_game_AI()
root.destroy()
root.mainloop()


In my loop, main_game_AI() runs, then I run the root.mainloop() for the tkinter gui to work. But I must use root.destroy(), so the loop continues. This works well for the first iteration. But when I put in the test inputs for the second iteration, I got the following error:



Traceback (most recent call last):
File "chineseCheckersAI.py", line 86, in <module>
main_game_AI()
File "chineseCheckersAI.py", line 77, in main_game_AI
canvas.move(black_id[checker_move],-23,-50)
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 2588, in move
self.tk.call((self._w, 'move') + args)
_tkinter.TclError: invalid command name ".!canvas"









share|improve this question
















Why do I get an error with my tkinter mainloop() about a invalid command name canvas? I am creating an AI board game, and I created a main loop. I use 2 lists for my checker id's, black_id, and white_id, just not portrayed here:



def main_game_AI():
print("Read the README file first to learn how to move.")
move = input("What do you move?:")
checker_move = int(move)
where = input("What direction will you move?:")
canvas.move(black_id[checker_move],-23,-50)
print("Robot: OOOOOOoooooh!! Tricky decision! I play:")
canvas.move(white_id[3], -23,50)
white3 = 18
print("We start with the",first_side,"side.")
while gameOn == True:
main_game_AI()
root.destroy()
root.mainloop()


In my loop, main_game_AI() runs, then I run the root.mainloop() for the tkinter gui to work. But I must use root.destroy(), so the loop continues. This works well for the first iteration. But when I put in the test inputs for the second iteration, I got the following error:



Traceback (most recent call last):
File "chineseCheckersAI.py", line 86, in <module>
main_game_AI()
File "chineseCheckersAI.py", line 77, in main_game_AI
canvas.move(black_id[checker_move],-23,-50)
File "/anaconda3/lib/python3.7/tkinter/__init__.py", line 2588, in move
self.tk.call((self._w, 'move') + args)
_tkinter.TclError: invalid command name ".!canvas"






python canvas tkinter while-loop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 6:49









cdlane

18.3k21144




18.3k21144










asked Nov 14 '18 at 6:00









F. ZengF. Zeng

219




219













  • Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

    – Bryan Oakley
    Nov 14 '18 at 8:42













  • Yes, but then, i can't update the canvas.

    – F. Zeng
    Nov 15 '18 at 5:10



















  • Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

    – Bryan Oakley
    Nov 14 '18 at 8:42













  • Yes, but then, i can't update the canvas.

    – F. Zeng
    Nov 15 '18 at 5:10

















Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

– Bryan Oakley
Nov 14 '18 at 8:42







Why are you trying to call mainloop in a loop? It should be called exactly once for the life of the program. You can't call it again once the window has been destroyed.

– Bryan Oakley
Nov 14 '18 at 8:42















Yes, but then, i can't update the canvas.

– F. Zeng
Nov 15 '18 at 5:10





Yes, but then, i can't update the canvas.

– F. Zeng
Nov 15 '18 at 5:10












0






active

oldest

votes











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%2f53294008%2fpython-tkinter-tclerror-from-root-mainloop-after-calling-root-destroy%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53294008%2fpython-tkinter-tclerror-from-root-mainloop-after-calling-root-destroy%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

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values