What screw size should be used to mount a TIP31 in a TO220 package to a bare PCB (no heatsink?) I presume a nut will also be required on the other side, so would appreciate a part number for that too. (I'm not too clued up on mechanical stuff, so go easy on me.)
Put the nut on top of the package so that any excess screw length sticks upwards.
It may be cheaper to buy machine screws (and nuts) of similar thickness at a nearby hardware store. My local screw dealer charges by weight, so I end up paying pennies (cents) for what I need in my hobby projects.
What matters most is that your screw fits in the mounting hole, which is about 3.5mm in diameter.
An M3 bolt is great, but you might also consider soldering the TO220 tab to a wide pad on the PCB. You'll get a little heatsinking (perhaps not necessary) and your project will have fewer parts to rattle loose.
If you do use a mechanical fastener and you're worried about it coming loose over time, you can use a nut with a nylon insert or a drop of Loctite 222 threadlocker for small fasteners. With longer bolts that are made of the same material as the nuts (for example, if you want both to be stainless steel), Loctite is a better choice. When the nut and bolt are the same material, the thread surface tends to gall, and the nylon insert makes it worse.