How Python uses turtle and tkinter to make baby turtles interact
This article mainly introduces how Python uses turtle and tkinter to make small turtles interact with each other. It has certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article. Let's take a look at it.
Turtle window
Take a look at the following figure. The turtle window icon is a small leaf, which is estimated to be inherited from the tkinter library.
Tkinter window
Referring to some materials, it is found that the turtle method can be operated directly on the canvas Canvas of tkinter:
Source code from tkinter import * from turtle import RawTurtle def circ (): tu.penup () tu.home () tu.clear () tu.speed (0) [x _ journal yjournal R] = et1.get () .split (',') try: X = int (x.replace ((',')) y = int (y.replace (')' ) R = int (R.strip ()) except: X tu.home () tu.clear () tu.speed (0) tu.color ('red') tu.color (0) tu.color (' red') 'yellow') tu.begin_fill () [dmemrad] = et2.get () .split (',') try: d = int (d) rad = int (rad) except: d Rad = 200216 # input error gives the default value tu.pendown () tu.back (dUnix 5) while True: tu.forward (d) tu.left (rad) if abs (tu.pos () [0] + dmax 5)