Hiermit wird ein einfaches Zeichenprogramm mit Turtel-Grafik-Funktionen realisiert - soweit wie wir beim letzten Kurs gekommen sind
import sys sys.setrecursionlimit(20000) from turtle import Turtle, Screen def fill_switch(xdummy, ydummy): if stift.filling(): stift.end_fill() stift.fillcolor("") else: stift.begin_fill() stift.fillcolor("red") def jump(x, y): stift.penup() stift.goto(x, y) stift.pendown() def colorButton(farbe, y): t = Turtle(visible=False) t.shape("square") t.speed(0) t.penup() t.goto(-340,y) t.fillcolor(farbe) def setpencolor(xdummy, ydummy): stift.pencolor(farbe) def setfillcolor(xdummy, ydummy): stift.fillcolor(farbe) t.onclick(setpencolor, 1) t.onclick(setfillcolor, 3) t.showturtle() # Anfang Hauptprogramm screen = Screen() screen.clear() screen.setup(800, 600) stift = Turtle() stift.speed(0) stift.shape("circle") stift.pensize(3) stift.shapesize(0.2,0.2,3) colorButton("red", 120) colorButton("blue", 80) screen.onclick(stift.goto) screen.onclick(jump, 2) screen.onclick(fill_switch, 3) screen.onkeypress(stift.undo, "BackSpace") screen.onkeypress(stift.clear, "space") for i in "123456789": def setpensize(ps=int(i)): stift.pensize(ps) stift.shapesize(0.2 + ps/10) screen.onkeypress(setpensize, i) screen.listen() stift.ondrag(stift.goto)