With some searching in the forum you can usually find existing solutions that can help directly or indirectly with finding what you need.
For example see this post that mentions about the box in the 3D view.
Also consult the Slicer script repository for examples of common tasks that can help guide you even if it is not exactly what you desire. For example here is how to change the box color, but changing box visibility could be inferred from that example.