Wednesday 13 February 2019

Changing Colours

img_a_01

Well, in this opportunity I got some simple animation that involves a straight line that change its colour between 4 options in a fixed order, it's a relatively simple task, although I've seen codes that involve the use of objects and classes, so I hope to get a better understanding on them before posting about it.

Anyway, the next are the code lines used for the changing colours animation:


import time
from Tkinter import *
root = Tk()

c1 = Canvas(root, height = 200, width = 200, bg = 

"black")

colours = ["white", "red", "yellow", "blue"]

c1.pack()

for i in range(0, 1000):
    for sprite in colours:
        c1.delete(ALL)
        c1.create_line(40, 50, 100, 110, fill = sprite  , 

width = 3)
        c1.update()
        time.sleep(0.9)

root.title("Lines")
root.mainloop()
 
img_01

:D


No comments:

Post a Comment