Skip to main content

from turtle import Turtle

from turtle import Turtle, Screen
xmax=250
ymax=250
file = open("testfile.txt","w")
def konec():
   print("konec")
   t.bye()
def tazeni(x, y):
    t.ondrag(None)
    t.setheading(t.towards(x, y))
    if abs(x)>xmax and x>0:
        x=xmax
    if abs(x)>xmax and x<0:
        x=xmax*-1
    if abs(y)>ymax and y>0:
        y=xmax
    if abs(y)>ymax and y<0:
        y=xmax*-1
    print("x",x,"y",y)   
    t.goto(x, y)
    #t.onkey(konec, "q")
    t.ondrag(tazeni)

obrazovka = Screen()
obrazovka.setup(2*xmax+20,2*ymax+20)
t = Turtle('turtle')
t.speed('fastest')
t.ondrag(tazeni)

obrazovka.mainloop()