Get the App
SLTechnology News&Howtos  ›  Development  › 

How Python uses turtle and tkinter to make baby turtles interact

Shulou Source: shulou.com Published: 2022-06-01 10:02:02 10月02日 Update

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)

Tags: Article Xiaohai error input polygon control diameter tai chi three the following picture value interest parameter leaf at the same time icon center coordinates tai chi map that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Information Huawei Shulou Tech Info