An example of python using tkinter to make animation effects

import time      
from tkinter import*
tk=Tk() #Create a frame object tk
canvas=Canvas(tk,width=500,height=500) #Create a canvas object canvas, which belongs to the tk object
canvas.pack() #The canvas object Update shows in frame
canvas.create_polygon(10,10,10,60,50,35) 
#Create a polygon, vertex coordinates (x1, y1, x2, y2, x3, y3), which belong to the canvas object,
#The default graphic number is 1, which is used for function calls, and the sequence of subsequent graphic numbers is analogous.
for i in range(0,60): #Create a loop for 60 times, loop interval [0,59)
    canvas.move(1,5,0) #The number "1" in the canvas object calls the move function, the x-axis is 5 pixels, and the y-axis remains unchanged
    tk.update() #Update the frame, force the display to change
    time.sleep (0.05) #Sleep for 0.05 seconds, making the interval time between frames
for i in range(0,60):                                                   
    canvas.move(1,0,5)
    tk.update()
    time.sleep(0.05)
for i in range(0,60):
    canvas.move(1,-5,0)
    tk.update()
    time.sleep(0.05)
for i in range(0,60):
    canvas.move(1,0,-5)
    tk.update()
    time.sleep(0.05)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325504525&siteId=291194637