Use Tkinter to create GUI development tools (32) Turtle component in Tkinter

Use Tkinter to create GUI development tools (32) Turtle component in Tkinter


As we introduced earlier, a lot of drawing software is built on the basis of Tkinter, so can
Turtle be run in Tkinter? Of course it can. In the support module of HP_tk2, we have this module HP_turtle. Using the HP_turtle module, you can execute the turtle command in the Tkinter window.
The demo code is given below.

import tkinter as tk
import HP_turtle as hte

if __name__=="__main__":
    root=tk.Tk()
    root.title('HP_turtle演示') 
    ht=hte.turtleview(root,bg='black')
    ht.pack()
    t=ht.pen
    ht.bgcolor("black")
    sides=6
    colors=["red","yellow","green","blue","orange","purple"]
    for x in range(85):
        t.pencolor(colors[x%sides])
        t.forward(x*3/sides+x)
        t.left(360/sides+1)
        t.width(x*sides/200)    
        root.update()
        t.speed(1)

The results of the software operation are shown in the figure below.
Insert picture description here
Insert picture description here
Therefore, we can place this control in the Tkinter window of our software to realize the turtle drawing function.

Guess you like

Origin blog.csdn.net/hepu8/article/details/106322590