Simple "On Tap" with Widgets in Swift?

Hey everyone! I'm new to Swift and iOS development in general, and I'm trying to experiment with widgets and the different functionality they can offer.

Is there any way that I can tap a widget, and instead of opening the app, it'll run a function I've created to, say, open a different app, toggle a setting, etc.?

I tried creating a button in the widget's Entry View but that didn't work because tapping on the widget still opened the app.

Any help would be greatly appreciated!

Simple "On Tap" with Widgets in Swift?
 
 
Q