Yes, that's the function of either a dedicated transfer switch, or a backfeed breaker interlock.
The breaker interlock prevents the backfeed breaker from being closed until the main breaker is opened.
Given that the backfeed breaker has to be installed into the panel close to the main breaker for the physical interlock to function, it could take some circuits rearranging to implement. And, provided local authority allows the interlock method.
There are various styles but here's an example where you can see the main breaker has to be opened/off before the blocker can be lifted to close the backfeed breaker.
And, conversely, the main can't be closed until the backfeed is opened and the main block cleared.
View attachment 840465