Mary57, by train you are definitely NOT limited to towns right along the Rhine River. Many railways criss-cross the Black Forest, and it's a great place to travel by train.
Here is the Rhine Valley Railway:
https://en.wikipedia.org/wiki/Mannheim%E2%80%93Karlsruhe%E2%80%93Basel_railway#/media/File:Karte_Rheintalbahn.png
From Offenburg on the map above, you can travel the Black Forest Railway to the eastern edge of the Black Forest and beyond to visit towns like Gutach, Haslach, Hausach, Hornberg, Triberg, Villingen and Donaueschingen. See map:
https://de.wikipedia.org/wiki/Schwarzwaldbahn_%28Baden%29#/media/Datei:Verlaufskarte_Schwarzwaldbahn_(Baden).png
From Freiburg you can head east on the Hell Valley Railway to towns like Kirchzarten, Hinterzarten, Titisee, Loeffingen, and Donaueschingen. See map:
https://en.wikipedia.org/wiki/H%C3%B6llentalbahn_%28Black_Forest%29#/media/File:Verlaufskarte_H%C3%B6llentalbahn_2.png
Look back at the Black Forest Railway and find Hausach. From Hausach you can travel along the Kinzig Valley Railway to Wolfach, Alpirsbach, Schiltach and Freudenstadt. See map:
https://de.wikipedia.org/wiki/Datei:Verlaufskarte_Kinzigtalbahn.png
There are other railways elsewhere as well, but these are perhaps the most common ones that visitors need to know about.
The KONUS card permits unlimited travel on all the Black Forest train lines as well as any connecting buses you might need. The card comes free of charge with your room when you stay in certain Black Forest towns which participate in this promotion (which number about 140 towns.) (Staying in Freiburg or in Offenburg will NOT get you this free rail pass. Participating towns are listed on the flyer below:
https://www.schwarzwald-tourismus.info/_Resources/Persistent/0c3472a9b49af58668ca35c63dc764b4f6524504/KONUS%20Flyer_2026.pdf