Thank you Gadgetoid,
I plan a slider onscreen to go between 25 and 255 and your code Is mighty helpful.
To avoid having to figure out this from scratch, I had planned a set of files, each containing one of six brightness levels and from within the python software, copy the relevant file to the brightness file to set the matching brightness according to an onscreen slider.
However now I can use your example to do it directly to the file.
In a future version, I may link it to a light sensor too so that it darkens in proportion to the ambient light level. This would be a very useful set of capabilities to be built in. For now, your code is really helpful.
fyi I am building a specialised timepiece, so have added the Piface realtime clock shim, put a case around the Pi - hiding the activity lights to help keep it dark at night - and a nice short USB cable to patch power between the display and the Pi.
I tried the dual USB from Pimoroni, suggested elsewhere, but the plugs are too long and show up outside the frame - finding a right angled one hasn't been fruitful either.
It's a shame there isn't a suitable case or add on pi bow layers for a combined touchscreen and Pi with cables to make it look less like an IT project. i like the flotilla colour best.