Let G be a simple complex Lie group with Weyl group W. We give a formula for the character of W on the zero weight space of any finite dimensional representation of G. The formula involves partition functions, generalizing Kostant's partition function. On the elliptic set of W the partition functions are trivial. On the elliptic regular set, the character formula is a monomial product of certain co-roots, up to a constant equal to 0 or ±1. For a Coxeter element we recover Kostant's formula for this trace. If the long element w0=−1, our formula leads to a method for determining all representations of G for which the zero weight space is irreducible.