try:
    import tkinter
except ImportError:
    display_with_gui = None
else:

    def display_with_gui():
        pass
result = somecalc()
if display_with_gui:
    display_with_gui(result)
else:
    display_as_text(result)
Change Program Flow based on Available Libraries