How to resume the Turtle panel?

0

I'll explain the code before explaining the problem. Here's the question: the program starts to run and shows a window with the button "Elementary School" (this is detail for the project). You click the button and it opens two windows: the Turtle drawing panel and the command window. In the latter there are two text fields (only two for testing). The first is to walk forward x pixles and the second to turn right x degrees. Okay. I make my normal drawing. I close the Turtle window and I only get my command window. When I click on any command to reopen the Turtle panel, I have to click twice, because the first time the code gives an error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Diego Cândido\AppData\Local\Programs\Python\Python37\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:/Users/Diego Cândido/.PyCharmCE2018.2/config/scratches/Chat.py", line 13, in direita
    t.right(go)
  File "<string>", line 5, in right
turtle.Terminator

The second time it works normal. And so it goes ... I wanted to know how to correct that mistake. I've tried using turtle.done (), .bye () in several places, but none will. Here is the code below:

import turtle
from tkinter import *
import sys

def fundamental():
    import turtle as t
    t.home()
    def goahead():
        go = int(frente.get())
        t.forward(go)
    def direita():
        go = int(direita.get())
        t.right(go)

    janela2 = Tk()
    janela2.title("ENSINO FUNDAMENTAL")
    janela2.geometry("500x500")

    frente = Entry(janela2)
    frente.place(x=0, y = 50)

    btn_frente = Button(janela2, text="IR PARA FRENTE", command=goahead)
    btn_frente.place(x=0, y = 100)

    btn_direita = Button(janela2, text="DOBRAR À DIREITA",command=direita)
    btn_direita.place(x=0, y = 200)
    direita = Entry(janela2)
    direita.place(x=0, y = 150)

    screen = t.Screen()
    screen.exitonclick()

    janela2.mainloop()

janela = Tk()
janela.title("TURTLE FOR SCHOOLS")
janela.geometry("250x100")

bt1 = Button(janela, text="Ensino Fundamental", command=fundamental)
bt1.place(x=0,y=50)
janela.mainloop()
    
asked by anonymous 01.12.2018 / 13:49

0 answers