If I remember correctly, all train tickets are available in advance , or on the day from Train stations.
Possibly kiosk 14 ? at Colombo main station.
Alternatively you can use an online application through, [email protected] and collect from any station.
Hope that a help.
If you're getting the train from Colombo to Galle, make sure you get on at Maradana station (where the train originates). This will guarantee you a seat, whereas you'll be involved in a bunfight for seats with locals if you get on at Fort station. You can buy tickets in advance by turning up at the station - and the fares are super-cheap.