For a quantum system with time dependent boundary conditions, it is shown that the ef-fective Hamiltonian can be constructed in a simple way without any geometric treatemnt. In this paper the effective Hamiltonian, constructed in the above way, of quantum particle in a spherical box of varying radius is used to calculate the Berry phase of the wave function. We found that the effective Hamiltonian and original one are formally related with a static gauge transformation, the quantum states of the two Hamiltonians differ by a Berry phase.