#!/usr/bin/python # -*- coding: utf-8 -*- from tkinter import * import time from random import * window = Tk() sizex = 400 sizey = 600 canvas = Canvas(window, width = sizex, height = sizey) canvas.pack() x = 100 # initial left-most edge of first ball y = 30 # initial top-most edge of first ball r = 16 # ball diameter depx = 2 # displacement at each move in x direction depy = 0 # displacement at each move in y direction # create balls: no_particles = 20 dy = (sizey-2.*y)/(no_particles+1) # y initial separation between balls print(dy) ball_list = [] for i in range(no_particles): ball = canvas.create_oval(x,y,x+r,y+r,fill="blue") y = y+dy ball_list.append(ball) #moves no_moves = 100 for j in range(no_moves): for ball in ball_list: canvas.move(ball, depx, choice([-2, 2]) ) # canvas.move(ball, depx, depy) canvas.after(10) canvas.update() time.sleep(5) # on attend quelques secondes window.destroy()