When I execute this code I have 2 frames. Is there any way to display this in one root frame?
import pandas as pd
import mplfinance as mpf
from tkinter import *
root = Tk()
root.title("candle")
root.geometry('600x550')
def candle():
file = 'BTC-USD.csv'
data = pd.read_csv(file)
print(data.info())
data.Date = pd.to_datetime(data.Date)
data = data.set_index('Date')
print(data)
mpf.plot(data, type='candle', mav=(20),volume=True, style='yahoo')
button = Button(root, text="grapg", comand=candle())
button.pack()
root.mainloop()
CodePudding user response:
The approach that I have seen work most often is to call mpf.plot()
first, outside of tkinter, with kwarg returnfig=True
. Then use the figure returned by mpf.plot()
to create your tkinter canvas, something like this:
fig, axlist = mpf.plot(data,type='candle',mav=(20),volume=True,
style='yahoo',returnfig=True)
canvas = FigureCanvasTkAgg(fig)
See also