aegirhall / console-menu

A simple Python menu system for building terminal user interfaces.
MIT License
365 stars 58 forks source link

Function containing plt.show() from matplotlib crashes on execution by Function Item #48

Open Admin-NWIF opened 4 years ago

Admin-NWIF commented 4 years ago

I have a function that renders a graph from matplotlib, and if I pass that function into a Function-Item it just crashes and throws an NSException.

Relevant code:

def plotData():
    df = pd.read_csv("data/MSFT.csv")
    print (df['Adj Close'])
    df[['High', 'Open', 'Adj Close']].plot()
    plt.show()

equityFunctions = SelectionMenu([])
SymbolLookup = FunctionItem(text="Symbol Lookup", function=plotData, menu=equityFunctions)

Error: libc++abi.dylib: terminating with uncaught exception of type NSException

The print statement shows briefly, but the graph just crashes the function. I'm guessing this is because Function-Item is trying to return me to the most relevant menu as soon as I select it, which seems to be a functionality limitation. It would be pretty useless if I could only use Function-Item to execute one-off functions where I don't need to see any output.