Python Forum
tkinter window and turtle window error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter window and turtle window error
#1
I have a simple tkinter menu example that opens a new window on click.
When the Turtle window is opened it works fine the first time.
But when closed and opened again.
I get the following error and the turtle does not draw.
I need to figure out how to remove the turtle on exit some how.

$ python menu1.py 
circle
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "menu1.py", line 54, in turtle1
    t = turtle.Turtle()
  File "/usr/lib/python3.7/turtle.py", line 3816, in __init__
    visible=visible)
  File "/usr/lib/python3.7/turtle.py", line 2557, in __init__
    self._update()
  File "/usr/lib/python3.7/turtle.py", line 2660, in _update
    self._update_data()
  File "/usr/lib/python3.7/turtle.py", line 2646, in _update_data
    self.screen._incrementudc()
  File "/usr/lib/python3.7/turtle.py", line 1292, in _incrementudc
    raise Terminator
turtle.Terminator
Any ideas?

from tkinter import *
import turtle
root = Tk()

def circle(t,x,y):
	print("circle")
	t.down()
	t.color("#ff0000")
	for i in range (0,20):
		t.forward(10)
		t.rt(18)
		
def turtle1():
    x = 0; y = 0
    w = turtle.Screen()
    w.setup(1000, 700)
    w.clear()
    w.bgcolor("#ffffff")
    t = turtle.Turtle()
    circle(t,x,y)
    w.exitonclick()
   
def newWin1(): # new window definition
    newwin = Toplevel(root)
    display = Label(newwin, text="Window 1")
    display.pack()    

def newWin2(): # new window definition
    newwin = Toplevel(root)
    display = Label(newwin, text="Window 2")
    display.pack()    

button1 =Button(root, text ="Window 1", command =newWin1) 
button2 =Button(root, text ="Window 2", command =newWin2) 
button3 =Button(root, text ="Turtle Window", command =turtle1) 
button1.pack()
button2.pack()
button3.pack()

root.mainloop()
Reply
#2
Try turtle.reset(): https://docs.python.org/3/library/turtle...rtle.reset

I was able to close and re-open the window by calling reset before re-opening the window, so hopefully that helps.
Reply
#3
from tkinter import *
import turtle

 
def circle(t,x,y):
    print("circle")
    t.down()
    t.color("#ff0000")
    for i in range (0,20):
        t.forward(10)
        t.rt(18)
         
def turtle1():
    try:
        turtle.TurtleScreen._RUNNING = True
        x = 0; y = 0
        w = turtle.Screen()
        w.setup(800, 700)
        w.title("Welcome to the turtle zoo!")
        w.clear()
        w.bgcolor("#ffffff")
        w.visible = True
        t = turtle.Turtle()
        circle(t,x,y)
        w.exitonclick()
    finally:
        turtle.Terminator()


def newWin1(): # new window definition
    newwin = Toplevel()
    display = Label(newwin, text="Window 1")
    display.pack()    
 
def newWin2(): # new window definition
    newwin = Toplevel()
    display = Label(newwin, text="Window 2")
    display.pack()    
 

def main():

    root = Tk()
    import sys
    print(sys.version)
    button1 =Button(root, text ="Window 1", command =newWin1) 
    button2 =Button(root, text ="Window 2", command =newWin2) 
    button3 =Button(root, text ="Turtle Window", command =turtle1) 
    button1.pack()
    button2.pack()
    button3.pack()

    root.mainloop()


if __name__ == '__main__':
    main()
windows 8.1 , python 3.7.4
Reply
#4
Thank You balenaucigasa and nilamo !
Both posts helped!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tk window not displaying until loop has completed Ganga 8 1,191 Aug-09-2021, 06:42 PM
Last Post: Ganga
  [Tkinter] window full screen w/ taskbar at top... 3python 0 212 Aug-04-2021, 09:06 PM
Last Post: 3python
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 323 Aug-02-2021, 08:47 PM
Last Post: JayCee
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 2,411 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
  [PyQt] My WIndow isnt opening at all. SovietMilkerGenerak 1 890 Apr-24-2021, 12:25 PM
Last Post: Yoriz
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 1,189 Mar-24-2021, 10:00 PM
Last Post: deanhystad
  [Tkinter] mpv window freeze before video end rfeyer 7 815 Feb-20-2021, 09:34 PM
Last Post: rfeyer
  Subprocess window won't open on Mac blakefindlay 1 823 Feb-06-2021, 04:23 AM
Last Post: deanhystad
  "tkinter.TclError: NULL main window" Rama02 1 1,242 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  [PyQt] Opening new window ifigazsi 2 624 Jan-20-2021, 04:16 PM
Last Post: ifigazsi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020