kann mir wer bitte sagen wie ich mein mode_change definierenmuss damit ich zw line mode circle moe und freehand mode wechseln kann und sie nicht gleichzeitig zeichnen
und wieso mein linemode nicht funktioniert?
from turtle import Screen, Turtle
beni=Screen()
beni.setup(400, 400, 10, 10)
beni.setworldcoordinates(-300, -300, 300, 300)
Color = ['blue', 'green', 'red', 'yellow']
color_index = 1
Width = [1, 5, 10, 15]
width_index = 1
Modi = ['freehandmode', 'circlemode', 'linemode']
mode_index = 1
def colorswitch(x, y):
global color_index
color_index = (color_index + 1) % len(Color)
t.color(Color[color_index])
def width_change(x, y):
global width_index
width_index = (width_index + 1) % len(Width)
t.pensize(Width[width_index])
def mode_change(x, y):
t.pendown()
turtle.penup()
turtle.hideturtle()
#freehandmode
def freehandmode(x, y):
t.ondrag(None)
t.setheading(t.towards(x, y))
t.goto(x, y)
t.ondrag(freehandmode)
#linemode
class Drawer:
def __init__(self):
self.drawing = False
def click(self, x, y):
if self.drawing:
tu.down()
tu.goto(x, y)
self.drawing = False
else:
tu.up()
tu.goto(x, y)
self.drawing = True
d = Drawer()
beni.onclick(d.click)
#circlemode
def draw_circle(x, y):
beni.onclick(None)
center = turtle.position()
turtle.setposition(x, y)
turtle.setheading(turtle.towards(center) - 90)
turtle.pendown()
turtle.circle(turtle.distance(center))
turtle.penup()
turtle.clearstamps()
beni.onclick(pick_center)
def pick_center(x, y):
beni.onclick(None)
turtle.setposition(x, y)
turtle.stamp()
beni.onclick(draw_circle)
turtle = Turtle()
turtle.hideturtle()
turtle.shape('circle')
turtle.shapesize(0.5)
turtle.penup()
beni.onclick(pick_center)
#freehand turtle
t = Turtle('circle')
t.pensize(Width[width_index])
t.shapesize(1)
t.speed('fastest')
t.color(Color[color_index])
t.ondrag(freehandmode)
tu = Turtle("turtle")
#color change
colorchange = Turtle('circle')
colorchange.pu()
colorchange.shapesize(0.55, 1.45)
colorchange.color('black')
colorchange.setpos(-275, 290)
colorchange.onclick(colorswitch, 1)
#color button
colorbutton = Turtle()
colorbutton.shapesize(0.25)
colorbutton.pu()
colorbutton.setpos(-300, 300)
colorbutton.setheading(270)
colorbutton.pd()
colorbutton.fd(20)
colorbutton.setheading(0)
colorbutton.fd(45)
colorbutton.setheading(90)
colorbutton.fd(20)
colorbutton.setheading(180)
colorbutton.fd(45)
colorbutton.pu()
colorbutton.setpos(-293, 263)
colorbutton.setheading(0)
colorbutton.color('green')
colorbutton.write('Color')
colorbutton.hideturtle()
#turtle width change
change_width = Turtle('circle')
change_width.pu()
change_width.shapesize(0.55, 1.45)
change_width.color('black')
change_width.setpos(265, 290)
change_width.onclick(width_change, 1)
#linewidth button
thickness = Turtle('circle')
thickness.shapesize(0.25)
thickness.pu()
thickness.setpos(240, 300)
thickness.setheading(270)
thickness.pd()
thickness.fd(20)
thickness.setheading(0)
thickness.fd(45)
thickness.setheading(90)
thickness.fd(20)
thickness.setheading(180)
thickness.fd(45)
thickness.pu()
thickness.setpos(248, 263)
thickness.setheading(0)
thickness.color("green")
thickness.write('Width')
thickness.hideturtle()
#modechange turtle
modechange = Turtle('circle')
modechange.pu()
modechange.shapesize(0.55, 1.45)
modechange.color('black')
modechange.setpos(0, 290)
modechange.onclick(mode_change)
#modebutton
modebutton = Turtle()
modebutton.shapesize(0.25)
modebutton.pu()
modebutton.setpos(-20, 300)
modebutton.setheading(270)
modebutton.pd()
modebutton.fd(20)
modebutton.setheading(0)
modebutton.fd(45)
modebutton.setheading(90)
modebutton.fd(20)
modebutton.setheading(180)
modebutton.fd(45)
modebutton.pu()
modebutton.setpos(-10, 263)
modebutton.setheading(0)
modebutton.color('green')
modebutton.write('Modi')
modebutton.hideturtle()
beni.mainloop()