Is there a way to use two turtles at the same time to draw two circles at the same time in one window? I tried this code but two turtles draw in separated windows
from multiprocessing import Process
import turtle
t1=turtle.Turtle()
t2=turtle.Turtle()
def tes1():
t1.speed(0)
i=0
while i < 360:
t1.forward(1)
t1.left(1)
i+=1
def tes2():
t2.speed(0)
i=0
while i < 360:
t2.forward(1)
t2.right(1)
i+=1
if __name__ == '__main__':
p1 = Process(target=tes1)
p1.start()
p2 = Process(target=tes2)
p2.start()
p1.join()
p2.join()
but somebody told me try multithreading but this code has a bad semantic error!!
import threading
import turtle
t1=turtle.Turtle()
t2=turtle.Turtle()
def tes1():
t1.speed(0)
i=0
while i < 360:
t1.forward(1)
t1.left(1)
i+=1
def tes2():
t2.speed(0)
i=0
while i < 360:
t2.forward(1)
t2.right(1)
i+=1
t = threading.Thread(target=tes1)
t.daemon = True # thread dies when main thread (only non-daemon thread) exits.
t.start()
t3 = threading.Thread(target=tes2)
t3.daemon = True # thread dies when main thread (only non-daemon thread) exits.
t3.start()
And what is the best suggestion multiprocessing or multithreading?