http://www.mmrelearn...iew.php?id=4221
from Tkinter import*
import time
def sort():
x =100
y = 500
barWidth = 15
lst = [10, 25,5,15,30,20]
for item in lst:
bar = cv.create_rectangle(x, y, x+barWidth, y-(item*10), fill="red")
x += barWidth + 5
cv.update()
x= 100
y =500
for item in range(len(lst)-1, 0, -1):
for i in range(item):
if lst[i] > lst[i + 1]:
lst[i], lst[i + 1] = lst[i + 1], lst[i]
print lst
cv.delete(ALL)
for bars in lst:
time.sleep(0.1)
barSorted = cv.create_rectangle(x, y, x+barWidth, y-(bars*10), fill="red")
x += barWidth + 5
cv.update()
#MAIN
#Canvas
root = Tk()
root.title("Sorting Algorithm Animation")
w = 800
h = 600
cv = Canvas(width=w, height=h, bg='black')
cv.pack()
cv.update()
sort()
root.mainloop()

New Topic/Question
Reply




MultiQuote




|